admin管理员组

文章数量:1315314

I am using VeeValidate for validating a form. However, I want to submit the form without using JS. However, I still want users not to be able to submit, if there are any errors. If I use

<form @submit.prevent="validateBeforeSubmit">

it is disabling the default action pletely.

Can you think of any solution to this? Thank you!

I am using VeeValidate for validating a form. However, I want to submit the form without using JS. However, I still want users not to be able to submit, if there are any errors. If I use

<form @submit.prevent="validateBeforeSubmit">

it is disabling the default action pletely.

Can you think of any solution to this? Thank you!

Share Improve this question asked Jul 24, 2017 at 13:07 HillcowHillcow 9794 gold badges21 silver badges53 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

I'm not familiar with VeeValidate, but why not try something like this:

<form @submit="validateBeforeSubmit">
validateBeforeSubmit(e) {
  if (this.errors.any()) {
    // Prevent the form from submitting
    e.preventDefault();
  }
}

Try to add () for validateBeforeSubmit like this:

<form @submit="validateBeforeSubmit()">

本文标签: javascriptVuejs Prevent form submit only if condition trueStack Overflow