Commit 5425dc69 authored by luckyCao's avatar luckyCao Committed by hetech

Form: fix switching the rules in el-form not work (#14985) (#15017)

parent 3f0820d8
...@@ -279,6 +279,17 @@ ...@@ -279,6 +279,17 @@
}, },
updateComputedLabelWidth(width) { updateComputedLabelWidth(width) {
this.computedLabelWidth = width ? `${width}px` : ''; 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() { mounted() {
...@@ -293,12 +304,7 @@ ...@@ -293,12 +304,7 @@
value: initialValue value: initialValue
}); });
let rules = this.getRules(); this.addValidateEvents();
if (rules.length || this.required !== undefined) {
this.$on('el.form.blur', this.onFieldBlur);
this.$on('el.form.change', this.onFieldChange);
}
} }
}, },
beforeDestroy() { beforeDestroy() {
......
...@@ -49,6 +49,12 @@ ...@@ -49,6 +49,12 @@
}, },
watch: { watch: {
rules() { rules() {
// remove then add event listeners on form-item after form rules change
this.fields.forEach(field => {
field.removeValidateEvents();
field.addValidateEvents();
});
if (this.validateOnRuleChange) { if (this.validateOnRuleChange) {
this.validate(() => {}); this.validate(() => {});
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment