vee-validate: Custom validation rule is not run when running validateAll()
Versions:
- VueJs: 2.1.10
- Vee-Validate: 2.0.0-beta.22
Description:
Following the coupon example validation from the docs, I created a custom validation function, but when I call this.$validator.validateAll() the custom validation is ignored. Does it need to be registered anywhere? The coupon example manually attached the rule, where as I’m using v-validate on the input itself, seeing as I have multiple inputs that require the custom validation.
Steps To Reproduce:
- Create custom validator
- Attach to input using
v-validate="'custom_validation'" - Run
this.$validator.validateAll()from a method on the component. - Custom validation not run.
Please note, it does run when the input is changes, but NOT via validateAll().
Do I need to register it somewhere for this to work?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (6 by maintainers)
@christippett
Validate all works by attempting to resolve the values for the attached fields, when it fails to resolve a value it ignores the field. The value resolution is done through getters that should be passed in the options object when attaching the field, that way you are teaching the validator how to resolve the value for the field when it needs to.
I’ve updated the example to use
RC.8and include the getter for that field.https://jsfiddle.net/logaretm/e8yrk5zu/7/
I realize this is hardly documented and will be resolved soon with the rework of the docs.
Its working as expected as far as I can tell https://jsfiddle.net/logaretm/e8yrk5zu/
Notice that the third one is the only one that gets validated, because it is a required value. The validator skips any checks if the field has empty value and if its not required so your rule does not execute until it has a non-empty value in it.