From 9756a3c33a7af73f937e259834c58f1633707085 Mon Sep 17 00:00:00 2001 From: baiyaaaaa Date: Thu, 15 Jun 2017 19:34:45 +0800 Subject: [PATCH] support dynamic form item rule required --- packages/form/src/form-item.vue | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/form/src/form-item.vue b/packages/form/src/form-item.vue index 74b3aba2..84feeb5e 100644 --- a/packages/form/src/form-item.vue +++ b/packages/form/src/form-item.vue @@ -112,6 +112,21 @@ 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() { @@ -119,8 +134,7 @@ validateState: '', validateMessage: '', validateDisabled: false, - validator: {}, - isRequired: false + validator: {} }; }, methods: { @@ -211,12 +225,6 @@ 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); }