Skip to content
Oscar edited this page Nov 14, 2018 · 5 revisions

Paths are reached through the shorthand variable $vd in the component.

Validating

To validate a defined path use that path and call $validate which will return a promise.

Remember that promises must have resolve and reject functions.

Giving the following data structure:

data: () => ({
   owner: {
      name: undefined,
      email: undefined
   },

   phones: [
      '123456789',
      '987654321'
   ],

   addressBook: [{
      name: 'name 1',
      addres: 'addres 1'

   }, {
      name: 'name 1',
      addres: 'addres 1'
   }]
})

To validate just the owner data we would use:

this.$vd.owner.$validate().then(() => {
   // Owner data is correct

}).catch(() => {
   // Owner data has errors
});

To validate just the addres book:

this.$vd.addressBook.$validate().then(() => {
   // Address book data is correct

}).catch(() => {
   // Some address book data has error
});

To validate all the data:

this.$vd.$validate().then(() => {
   // All data is correct

}).catch(() => {
   // Some data has error
});

Validation path properties

For each validation path having rules you can retrieve the following properties

Property Description
$validated Indicates if it has been already validated
$hasError Indicates if has any error
$error Will return the first error message
$errors Return an array of error messages

This are mostly used in the template to display the error of a related field.

You can also retrieve $errors from a parent path and will get an object with the path as key and an array of error messages for each child with errors.