6

I have a global validation rule, for example:

import { extend } from 'vee-validate';
import { required } from 'vee-validate/dist/rules';

extend('required', {
  ...required,
  message: 'Please fill the field'
});

This rule is using for all Vue components across the project. But for one exact component I need to redefine the message Please fill the field to another one. Is it possible to change the message just for one Vue component?

Ky6uk
  • 1,067
  • 3
  • 16
  • 26

1 Answers1

8

You can specifiy specific messages for each ValidationProvider component using the custom-messages prop

<ValidationProvider rules="required" :custom-messages="{ required: 'required message' }">
  <!-- ... -->
</ValidationProvider>

You can extract it on a data prop and use it for the providers in your component:

<template>
  <ValidationProvider rules="required" :custom-messages="customMessages">
    <!-- ... -->
  </ValidationProvider>

  <ValidationProvider rules="required" :custom-messages="customMessages">
    <!-- ... -->
  </ValidationProvider>
</template>

<script>
export default {
 // ....
 data: () => ({
    customMessages: {
      required: 'custom message'
    }
  }),
  // ...
};
</script>
logaretm
  • 1,345
  • 9
  • 12