Home > Back-end >  How can you set a global validation rule with FormKit
How can you set a global validation rule with FormKit

Time:11-17

I am creating forms with FormKit and using the Schema to build up the forms.

We need to make it so the required validation rule is a generic message This field is required, rather than [field] is required

Is there a way to globally update that, rather than having to pass this to every field?

CodePudding user response:

Yes, you can change this by overriding the global config. Wherever you are registering FormKit:

import { createApp } from 'vue'
import { plugin, defaultConfig } from '@formkit/vue'
import App from 'App.vue'

createApp(App).use(plugin, defaultConfig({
  messages: {
    en: {
      validation: {
        required: 'This field is required'
      }
    }
}).mount('#app')

This was pulled from the docs here: https://formkit.com/essentials/validation#global-validation-message

  • Related