javascript - How to validate data only after button click? - Stack Overflow

I need to validate inputs only after a submit button is clicked. However, the required rule is activati

I need to validate inputs only after a submit button is clicked. However, the required rule is activating after focus lost. I'm using VeeValidate in Vue.js.

HTML:

<input 
  name="Email" 
  v-validate 
  data-vv-rules="required|email" 
  id="email" 
  type="email" 
  v-model="email" 
  placeholder="Email " 
>

JS:

this.$validator.validateAll().then(success => {

})

I need to validate inputs only after a submit button is clicked. However, the required rule is activating after focus lost. I'm using VeeValidate in Vue.js.

HTML:

<input 
  name="Email" 
  v-validate 
  data-vv-rules="required|email" 
  id="email" 
  type="email" 
  v-model="email" 
  placeholder="Email " 
>

JS:

this.$validator.validateAll().then(success => {

})
Share Improve this question edited Mar 22, 2017 at 14:47 thanksd 55.7k23 gold badges165 silver badges154 bronze badges asked Mar 22, 2017 at 13:20 MAXIMANMAXIMAN 1652 silver badges14 bronze badges 2
  • could you post ur full js function .. – Abhinav Commented Mar 22, 2017 at 13:23
  • From a UX standpoint, instant feedback after losing focus gives the form a nice interactive feel to it. This isn't the most helpful for the question but it's useful to be said. – Patrick Barr Commented Mar 22, 2017 at 13:28
Add a ment  | 

2 Answers 2

Reset to default 3

You can use data-vv-validate-on to disable the default validation behavior like so: data-vv-validate-on="none"

Then add a click event handler to your submit button a @click="submit".

And the submit method for your ponent would look something like this:

methods: {
  submit() {
    this.$validator.validateAll().then(success => {
      // submit the value
    })
  }
}

If your version of vee-validate < 4, this might help

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745360006a4624313.html

相关推荐

  • javascript - How to validate data only after button click? - Stack Overflow

    I need to validate inputs only after a submit button is clicked. However, the required rule is activati

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信