support dynamic form item rule required

This commit is contained in:
baiyaaaaa 2017-06-15 19:34:45 +08:00 committed by 杨奕
parent a54b5e626e
commit 9756a3c33a

View File

@ -112,6 +112,21 @@
return getPropByPath(model, path).v; return getPropByPath(model, path).v;
} }
},
isRequired() {
let rules = this.getRules();
let isRequired = false;
if (rules && rules.length) {
rules.every(rule => {
if (rule.required) {
isRequired = true;
return false;
}
return true;
});
}
return isRequired;
} }
}, },
data() { data() {
@ -119,8 +134,7 @@
validateState: '', validateState: '',
validateMessage: '', validateMessage: '',
validateDisabled: false, validateDisabled: false,
validator: {}, validator: {}
isRequired: false
}; };
}, },
methods: { methods: {
@ -211,12 +225,6 @@
let rules = this.getRules(); let rules = this.getRules();
if (rules.length) { if (rules.length) {
rules.every(rule => {
if (rule.required) {
this.isRequired = true;
return false;
}
});
this.$on('el.form.blur', this.onFieldBlur); this.$on('el.form.blur', this.onFieldBlur);
this.$on('el.form.change', this.onFieldChange); this.$on('el.form.change', this.onFieldChange);
} }