Merge pull request #358 from baiyaaaaa/feat-form

fix form validate bug
This commit is contained in:
杨奕 2016-10-12 19:12:37 +08:00 committed by GitHub
commit ceed04d3a2
2 changed files with 20 additions and 16 deletions

View File

@ -514,7 +514,7 @@
<el-option label="区域二" value="beijing"></el-option>
</el-select>
</el-form-item>
<el-form-item label="活动时间">
<el-form-item label="活动时间" required>
<el-col :span="11">
<el-form-item prop="date1">
<el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>

View File

@ -127,9 +127,12 @@
}
},
getRules() {
if (!this.prop) { return []; }
var rules = this.rules || (this.form.rules ? this.form.rules[this.prop] : []);
return Array.isArray(rules) ? rules : [rules];
var formRules = this.form.rules;
var selfRuels = this.rules;
formRules = formRules ? formRules[this.prop] : [];
return [].concat(selfRuels || formRules || []);
},
getFilteredRule(trigger) {
var rules = this.getRules();
@ -151,21 +154,22 @@
}
},
mounted() {
var rules = this.getRules();
rules.every(rule => {
if (rule.required) {
this.isRequired = true;
return false;
}
});
if (this.prop) {
this.dispatch('form', 'el.form.addField', [this]);
}
this.$on('el.form.blur', this.onFieldBlur);
this.$on('el.form.change', this.onFieldChange);
let rules = this.getRules();
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.change', this.onFieldChange);
}
}
},
beforeDestroy() {
this.dispatch('form', 'el.form.removeField', [this]);