mirror of https://github.com/ElemeFE/element
parent
3f0820d839
commit
5425dc69fe
|
@ -279,6 +279,17 @@
|
|||
},
|
||||
updateComputedLabelWidth(width) {
|
||||
this.computedLabelWidth = width ? `${width}px` : '';
|
||||
},
|
||||
addValidateEvents() {
|
||||
const rules = this.getRules();
|
||||
|
||||
if (rules.length || this.required !== undefined) {
|
||||
this.$on('el.form.blur', this.onFieldBlur);
|
||||
this.$on('el.form.change', this.onFieldChange);
|
||||
}
|
||||
},
|
||||
removeValidateEvents() {
|
||||
this.$off();
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
@ -293,12 +304,7 @@
|
|||
value: initialValue
|
||||
});
|
||||
|
||||
let rules = this.getRules();
|
||||
|
||||
if (rules.length || this.required !== undefined) {
|
||||
this.$on('el.form.blur', this.onFieldBlur);
|
||||
this.$on('el.form.change', this.onFieldChange);
|
||||
}
|
||||
this.addValidateEvents();
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
|
|
|
@ -49,6 +49,12 @@
|
|||
},
|
||||
watch: {
|
||||
rules() {
|
||||
// remove then add event listeners on form-item after form rules change
|
||||
this.fields.forEach(field => {
|
||||
field.removeValidateEvents();
|
||||
field.addValidateEvents();
|
||||
});
|
||||
|
||||
if (this.validateOnRuleChange) {
|
||||
this.validate(() => {});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue