Skip to content

Commit 53cb79e

Browse files
committed
feat(form): support submitAlwaysValidate prop
submitAlwaysValidate to control validate always when submit
1 parent 80a05dc commit 53cb79e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/components/form/form.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
immediateValidate: {
5656
type: Boolean,
5757
default: false
58+
},
59+
submitAlwaysValidate: {
60+
type: Boolean,
61+
default: false
5862
}
5963
},
6064
data() {
@@ -85,6 +89,15 @@
8589
}
8690
return groups
8791
},
92+
fieldsData() {
93+
return this.groups.reduce((fields, group) => {
94+
group.fields.reduce((fields, field) => {
95+
fields.push(field)
96+
return fields
97+
}, fields)
98+
return fields
99+
}, [])
100+
},
88101
layout() {
89102
const options = this.options
90103
const layout = (options && options.layout) || LAYOUTS.STANDARD
@@ -156,7 +169,7 @@
156169
this.$emit(EVENT_INVALID, this.validity)
157170
}
158171
}
159-
if (this.valid === undefined) {
172+
if (this.submitAlwaysValidate || this.valid === undefined) {
160173
this._submit(submited)
161174
if (this.validating || this.pending) {
162175
// async validate
@@ -299,7 +312,8 @@
299312
})
300313
},
301314
addField(fieldComponent) {
302-
this.fields.push(fieldComponent)
315+
const i = this.fieldsData.indexOf(fieldComponent.field)
316+
this.fields.splice(i, 0, fieldComponent)
303317
const modelKey = fieldComponent.fieldValue.modelKey
304318
modelKey && this.setValidity(modelKey)
305319
},

0 commit comments

Comments
 (0)