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.
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.
Most helpful comment
@Inigo-Pascall This was a private API, you can use this instead: