Skip to content

Is there an example of how we can define custom validation rules? #1

@FamilyMan

Description

@FamilyMan

Sorry for creating an issue for this, I couldn't see a questions option.

Is there a way to add custom validation rules?

If I add /plugins/formkit.ts with

import { defaultConfig, plugin } from '@formkit/vue'
import isRange from '~/rules/isRange'

export default defineNuxtPlugin({
  parallel: true,
  setup: (nuxtApp) => {
    nuxtApp.vueApp.use(plugin, defaultConfig({
      rules: { isRange },
    }))
  },
})

and rules/isRange.ts

const isRange = function (node) {
  return node.value.length === 2
}

export default isRange

I don't know if this code is correct, but I also get:

WARN: Plugin has already been applied to target app.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions