Skip to content
Advertisement

Vuelidate: validate on click, not when field touched

I’m kinda new to vuelidate, and everything works fine, except I have no clue how to run validation only when the button Submit has been clicked. Right now it marks touched field red when you start providing any input and I’d like it to wait with that, till user wants to submit filled form.

Here’s what I’ve got up to now:

JavaScript
JavaScript
JavaScript

Advertisement

Answer

I could never really get used to the Vuelidate way of doing things, but, generally speaking, it works like this: https://monterail.github.io/vuelidate/#sub-basic-form

Setting it up like this allows you to have validation for each form input/element and then an overall check to see if the form is “dirty” and/or “invalid”

JavaScript

As far as using this in practice, one option would be to call validateform event on submit.

JavaScript

Then create a validateform method in your vue instance that checks

JavaScript

then either display errors or call the actual submit method

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement