Vee-validate: this.$validator.update doesn't work's for me ?

Created on 17 Apr 2018  ·  3Comments  ·  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.2.6
  • Vee-Validate: 2.0.6
  • Nuxt: :0.10.7

Description:

Before with the version Vee-Validate: 2.0.0-rc.3 and same vuejs & nuxt

everything was working fine
But since the migration nothing seems to work in fact the required validation field is not apply

Do you have an idea ?
If you need more details don't hesitate

// before
this.$validator.updateField(fields[key], isEmpty ? '' : 'required');

Steps To Reproduce:

// now
const getValidatorkey = (validator, name) => validator.fields.find({ name: name }).id;

export default {
    onSubmit(){
        this.rule(document.getElementById('formCreate').querySelectorAll('#bloc-address input, #bloc-address select'));
    }
    rule(inputs) {
      debugger;
      let isEmpty = true;
      let fields = ['postalCode', 'street', 'city', 'country'];

      for (let key in inputs) {
        if (typeof inputs[key].value !== 'undefined' && inputs[key].value !== '') {
          isEmpty = false;
        }
      }

      for (let key in fields) {
        // test if validate attribute is not already required
        if (this.clientConf[fields[key]]['validate'] !== 'required') {




          // new code


          this.$validator.update(getValidatorkey(this.$validator, fields[key]), {
            scope: isEmpty ? '' : 'required'
          });





        }
      }
    }
}
❔ question 📚 docs

Most helpful comment

Sorry about that, Its purpose has been changed, you can do the same like this:

const field = this.$validator.fields.find({ name: 'fieldName' });

field.update({ rules: 'newRules' });

https://jsfiddle.net/fgzjabpa/19/

All 3 comments

https://jsfiddle.net/fgzjabpa/10/

We want to dynamically add the rule 'required' on all fields when user submit the form.
I did not find any information about this in the documentation.

Thx

Sorry about that, Its purpose has been changed, you can do the same like this:

const field = this.$validator.fields.find({ name: 'fieldName' });

field.update({ rules: 'newRules' });

https://jsfiddle.net/fgzjabpa/19/

thank you for the rapide answer

Was this page helpful?
0 / 5 - 0 ratings