mirror of https://github.com/ElemeFE/element
Form-item: fix "required" attribute is not effective for validation
parent
0efb4a58d7
commit
2cf9c4e7a7
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue