Vee-validate: Adding an error to the errorbag does not update classes/validity

Created on 8 Feb 2018  ยท  4Comments  ยท  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.5.3
  • Vee-Validate: 2.0.3

Description:

Using this.errors.add('field', 'message'); should update the validity, aria attributes and classes of the referenced field.

Right now I'm resorting to ignoring the validity and relying on classes only, which get updated when you trigger setFlags on the field e.g.

this.errors.add('email', 'failed to do it');
let field = this.$validator._resolveField('email');
field.setFlags({invalid: true});

Unfortunately this does not correctly update the "validity" of the field as the updateCustomValidity looks for an id in the error object, which doesn't get added if you add the errors manually.

Steps To Reproduce:

https://jsfiddle.net/05w82rem/5/

โ” question

Most helpful comment

@Inigo-Pascall This was a private API, you can use this instead:

let field = this.$validator.fields.find({ name: 'email' });

All 4 comments

error bag is just an array wrapper, any state management is done by the validator, so you might want to wrap your errors inside a rule.

you can get the field id, you've done most of the work :)

let field = this.$validator._resolveField('email');
field.setFlags({invalid: true});
this.errors.add({
  field: 'email',
  msg: 'failed to do it',
  id: field.id,
  scope: field.scope
});

"this.$validator._resolveField is not a function"

@Inigo-Pascall This was a private API, you can use this instead:

let field = this.$validator.fields.find({ name: 'email' });

Oh I see, thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

triffer picture triffer  ยท  3Comments

YamenSharaf picture YamenSharaf  ยท  3Comments

ash0080 picture ash0080  ยท  3Comments

schel4ok picture schel4ok  ยท  3Comments

the94air picture the94air  ยท  3Comments