Skip to content

Custom messages

Oscar edited this page Feb 1, 2020 · 4 revisions

In a custom rule

In a custom rule, when the result is not valid, you can return a string, that will be the error message returned.

Example:

vdRules: {
   address: {
      field: 'Address',
      myCustomValidation(data, validation) {
         if (data !== 'anyValue')
            return true;

         return '{field} is not a valid {rule}';
      }
   }
}

With defined message

You can define a message for a path to be more specific.

vdRules: {
   address: {
      required: true,
      minlen: 5,
      field: 'Address',
      message: 'This will be a specific message'
   }
}

With own validators

If you have defined your own validators you can also add your messages to the already built ones.

To do so define the messages the following way in you component.

vdMessages: {
   customValidator: 'This is not a valid {rule}',
   myOtherValidator: '{field} has wrong value for {rule}'
}