Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error after form resetting vee validate 3

I am using vee-validate 3.1.1 and vue 2.5.17.

After successful form submission I am resetting the input

this.name = ''

But validation error message shows after resetting the input like the below image

enter image description here

There was same problem in vee-validate 2.* I had solved that with this code

this.$nextTick(() => {
    this.errors.clear();
})  
like image 322
Amir Hossain Avatar asked Oct 15 '25 20:10

Amir Hossain


2 Answers

//first reset your form values
this.name = '';
//then do this to reset your ValidationObserver
this.$nextTick(() => this.$refs.observer.reset());

This requires that you have your form inputs wrapped in a ValidationObserver with the attribute ref="observer". Otherwise, you'd want to call the reset method of each ValidationProvider you use, inside that same callback.

See here for the examples they give for vee-validate. The "Resetting Forms" covers what you are doing, and the next example shows what I'm talking about ("Programmatic Access with $refs").

like image 170
Ryley Avatar answered Oct 17 '25 10:10

Ryley


Following the Vee-validate 3 documentations it is recommended to reset the form after the animation frames are requested.

You could do something like this:

methods: {
    async reset() {
       this.name = '';
       requestAnimationFrame(() => {
          this.$refs.observer.reset();
       );
    }
}
like image 40
Frederiek Avatar answered Oct 17 '25 12:10

Frederiek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!