Form-item: fix "required" attribute is not effective for validation

pull/7387/head
Hoxton Lau 2017-09-28 17:52:38 +08:00 committed by 杨奕
parent 0efb4a58d7
commit 2cf9c4e7a7
1 changed files with 4 additions and 3 deletions

View File

@ -148,7 +148,7 @@
methods: {
validate(trigger, callback = noop) {
var rules = this.getFilteredRule(trigger);
if (!rules || rules.length === 0) {
if ((!rules || rules.length === 0) && !this._props.hasOwnProperty('required')) {
callback();
return true;
}
@ -194,10 +194,11 @@
getRules() {
var formRules = this.form.rules;
var selfRules = this.rules;
var requiredRule = this._props.hasOwnProperty('required') ? { required: !!this.required } : [];
formRules = formRules ? formRules[this.prop] : [];
return [].concat(selfRules || formRules || []);
return [].concat(selfRules || formRules || []).concat(requiredRule);
},
getFilteredRule(trigger) {
var rules = this.getRules();
@ -232,7 +233,7 @@
let rules = this.getRules();
if (rules.length) {
if (rules.length || this._props.hasOwnProperty('required')) {
this.$on('el.form.blur', this.onFieldBlur);
this.$on('el.form.change', this.onFieldChange);
}