form-item watch rules change change rules
This commit is contained in:
parent
b50e59f509
commit
f203b14f9f
1 changed files with 16 additions and 12 deletions
|
@ -90,6 +90,9 @@
|
||||||
},
|
},
|
||||||
validateStatus (val) {
|
validateStatus (val) {
|
||||||
this.validateState = val;
|
this.validateState = val;
|
||||||
|
},
|
||||||
|
rules (val){
|
||||||
|
this.setRules();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
inject: ['form'],
|
inject: ['form'],
|
||||||
|
@ -143,6 +146,18 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
setRules() {
|
||||||
|
let rules = this.getRules();
|
||||||
|
if (rules.length) {
|
||||||
|
rules.every((rule) => {
|
||||||
|
this.isRequired = rule.required;
|
||||||
|
});
|
||||||
|
this.$off('on-form-blur', this.onFieldBlur);
|
||||||
|
this.$off('on-form-change', this.onFieldChange);
|
||||||
|
this.$on('on-form-blur', this.onFieldBlur);
|
||||||
|
this.$on('on-form-change', this.onFieldChange);
|
||||||
|
}
|
||||||
|
},
|
||||||
getRules () {
|
getRules () {
|
||||||
let formRules = this.form.rules;
|
let formRules = this.form.rules;
|
||||||
const selfRules = this.rules;
|
const selfRules = this.rules;
|
||||||
|
@ -229,18 +244,7 @@
|
||||||
value: this.fieldValue
|
value: this.fieldValue
|
||||||
});
|
});
|
||||||
|
|
||||||
let rules = this.getRules();
|
this.setRules();
|
||||||
|
|
||||||
if (rules.length) {
|
|
||||||
rules.every(rule => {
|
|
||||||
if (rule.required) {
|
|
||||||
this.isRequired = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.$on('on-form-blur', this.onFieldBlur);
|
|
||||||
this.$on('on-form-change', this.onFieldChange);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue