diff --git a/examples/docs/zh-cn/form.md b/examples/docs/zh-cn/form.md index 3a0a043b..592dd78d 100644 --- a/examples/docs/zh-cn/form.md +++ b/examples/docs/zh-cn/form.md @@ -514,7 +514,7 @@ - + diff --git a/packages/form/src/form-item.vue b/packages/form/src/form-item.vue index 3c5f2f94..e63d89ed 100644 --- a/packages/form/src/form-item.vue +++ b/packages/form/src/form-item.vue @@ -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]);