Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear errors object in vee-validate?

Tags:

vue.js

I'd like to clear all the errors from vee-validate in a sign out method, following code seems not working, the errors in the form is still being shown, why?

sign_out: function (e) {
    console.log('sign me out')
    var self = this
    firebase.auth().signOut().then(function () {

      console.log('sign out!')         
      self.info.email = ''
      self.errors.clear()  // clear errors object of vee-validate

    }, function (error) {

      console.log('sign out failed')

    })
  },

here is a jsFiddle that describe the problem in code, when you type '123', a warning is shown, then when you click 'clear', the field is set to '', and errors.clear(), was expecting the warning in the form will go away, but it is not:

https://jsfiddle.net/8j3z82bv/1/

like image 805
AngeloC Avatar asked Mar 07 '17 02:03

AngeloC


People also ask

What is Validator error?

A validation error occurs when you have validation/response checking turned on for one of the questions and the respondent fails to answer the question correctly (for numeric formatting , required response).

How do you use V validation?

All you need is to add the v-validate directive to the input you wish to validate and make sure your input has a name attribute for error messages generation. Then, pass to the directive a rules string which contains a list of validation rules separated by a pipe ' | '.

What is V validation?

Verification and validation (also abbreviated as V&V) are independent procedures that are used together for checking that a product, service, or system meets requirements and specifications and that it fulfills its intended purpose. These are critical components of a quality management system such as ISO 9000.


2 Answers

I have come up with another solution that could help. in your input we'll add another listener so it will be like this:

<input type="email" name="email" v-model="info.email" v-validate="'required|email'" @input="validate">

then will add the validate function that call vee-validate function so your vue instance will be something like this:

var app = new Vue({
    el: '#app',
    data: {
        info: { email: '' }
    },

    methods: {

        onSignin: function (e) { },
        clear_proc: function (e) {
            delete this.info.email

            this.errors.clear()
        },
        validate: function () {
          this.$validator.validateAll();
        }
    }
})
like image 165
Amr Aly Avatar answered Sep 28 '22 08:09

Amr Aly


Version (3.x)

this.$refs.observer.reset();

like image 29
Nana Adjei Avatar answered Sep 28 '22 06:09

Nana Adjei