Vee-validate: Check all fields before submit

Created on 7 Mar 2017  路  2Comments  路  Source: logaretm/vee-validate

Versions:

  • VueJs: ^2.0.1
  • Vee-Validate: 2.0.0-beta.21

Description:

How do you usually to force a validation of fields in the form before you submit the form? Because the form that i am building leave that user click in the submit button without click in any other field.

I searched and dont finded the answer.

Steps To Reproduce:

I do not see the need

Most helpful comment

It depends, if your component has only one form you can do this:

this.$validator.validateAll().then(() => {
 // success
}).catch(() => {
 // Failed
});

http://vee-validate.logaretm.com/examples#validate-form

if your component has multiple forms and you want to validate one in particular, you need to add data-vv-scope attribute on the forms and:

this.$validator.validateAll('scope').then(() => {
 // success
}).catch(() => {
 // Failed
});

http://vee-validate.logaretm.com/examples#scope-example

All 2 comments

It depends, if your component has only one form you can do this:

this.$validator.validateAll().then(() => {
 // success
}).catch(() => {
 // Failed
});

http://vee-validate.logaretm.com/examples#validate-form

if your component has multiple forms and you want to validate one in particular, you need to add data-vv-scope attribute on the forms and:

this.$validator.validateAll('scope').then(() => {
 // success
}).catch(() => {
 // Failed
});

http://vee-validate.logaretm.com/examples#scope-example

It worked as expected, thank you and sorry I had the example in the documentation.

Was this page helpful?
0 / 5 - 0 ratings