Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom errors to vee validator(ErrorBag)

Is it possible to add custom errors into the ErrorBag

I am using nuxtjs. i have registered vee-validate into my plugin via nuxt.config.js

It works fine However

I want to use the same error code within the template

ex:

 <template>
   <div v-if="errors.all().length>0">
       //loop through
   </div>
 </template>

i am using axios to fetch user information. if the request doesnt return my expected data set. i was thinking i could simply

 this.errors.push('this is my error message') //-> or some variant of this

When i do this i get that this.errors.push is not a function

I know that

this.errors = ErrorBag{ __ob__: Observer} //-> has items and a vmId attributes

If i amend the code to push onto ErrorBag i get push of undefined

like image 284
Jujubes Avatar asked Oct 18 '25 05:10

Jujubes


1 Answers

It is documented in the API of ErrorBag. You can add custom messages such as:

// For example, you may want to add an error related to authentication:
errors.add({
  field: 'auth',
  msg: 'Wrong Credentials'
});

Check the documentation here for more info: https://vee-validate.logaretm.com/v2/api/errorbag.html

like image 75
Seaskyways Avatar answered Oct 21 '25 09:10

Seaskyways