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');
// 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'
});
}
}
}
}
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' });
thank you for the rapide answer
Most helpful comment
Sorry about that, Its purpose has been changed, you can do the same like this:
https://jsfiddle.net/fgzjabpa/19/