From 53cb79ed1e6114d8a713bfab71670106022e350e Mon Sep 17 00:00:00 2001 From: dolymood Date: Mon, 17 Feb 2020 16:27:01 +0800 Subject: [PATCH] feat(form): support submitAlwaysValidate prop submitAlwaysValidate to control validate always when submit --- src/components/form/form.vue | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/form/form.vue b/src/components/form/form.vue index 9788b3b4..0c2450f5 100644 --- a/src/components/form/form.vue +++ b/src/components/form/form.vue @@ -55,6 +55,10 @@ immediateValidate: { type: Boolean, default: false + }, + submitAlwaysValidate: { + type: Boolean, + default: false } }, data() { @@ -85,6 +89,15 @@ } return groups }, + fieldsData() { + return this.groups.reduce((fields, group) => { + group.fields.reduce((fields, field) => { + fields.push(field) + return fields + }, fields) + return fields + }, []) + }, layout() { const options = this.options const layout = (options && options.layout) || LAYOUTS.STANDARD @@ -156,7 +169,7 @@ this.$emit(EVENT_INVALID, this.validity) } } - if (this.valid === undefined) { + if (this.submitAlwaysValidate || this.valid === undefined) { this._submit(submited) if (this.validating || this.pending) { // async validate @@ -299,7 +312,8 @@ }) }, addField(fieldComponent) { - this.fields.push(fieldComponent) + const i = this.fieldsData.indexOf(fieldComponent.field) + this.fields.splice(i, 0, fieldComponent) const modelKey = fieldComponent.fieldValue.modelKey modelKey && this.setValidity(modelKey) }, -- GitLab