Vee-validate: Custom component required validation on form submit

Created on 29 Mar 2018  ยท  2Comments  ยท  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.5.16
  • Vee-Validate: 2.0.6

Description:

I have form with validation on form submit, using this.$validator.validateAll()) on root component. I set deffered validations so errors not appear immediately - e.g. using v-validate.disable="'required'" on text input.

My question is, how can I apply this deferred validation behaviour on custom components, where I control required validation rule myself (when component is filled and when not). If I use this.errors.add and this.errors.remove API, errors appear in errors object immediately, and I want them to appear after form submit.

โ” question

Most helpful comment

I found well working solution to manually attach and detach to validator providing getter for value:

this.$validator.attach(name: this.name, rules: 'required', getter: () => this.getValue() });

Found mentioning about attach with getter in docs but separate example would be very helpful for new users :)

All 2 comments

It should work the same for custom components if it does not then create an example for it in jsfiddle or codesandbox and I would more than happy to investigate it.

I found well working solution to manually attach and detach to validator providing getter for value:

this.$validator.attach(name: this.name, rules: 'required', getter: () => this.getValue() });

Found mentioning about attach with getter in docs but separate example would be very helpful for new users :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Shchepotin picture Shchepotin  ยท  3Comments

Hoagiex picture Hoagiex  ยท  3Comments

HunterJS-bit picture HunterJS-bit  ยท  3Comments

biapar picture biapar  ยท  3Comments

YamenSharaf picture YamenSharaf  ยท  3Comments