Skip to content

Commit 15226b6

Browse files
committed
fix(form): should sync validator value when submit
1 parent c104441 commit 15226b6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/components/form/form-item.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@
151151
}
152152
if ((!debounceTime && debounceTime !== 0) || debounceTime < 0 || this.fieldValue.trigger === 'blur') return
153153
this.getValidatorModel = debounce((modelValue) => {
154-
this.pending = false
155-
this.validatorModel[this.validatorModelKey] = modelValue
156-
this.form.updatePending()
154+
this.syncValidatorValue()
157155
this.validate()
158156
return modelValue
159157
}, debounceTime, false, this.validatorModel[this.validatorModelKey])
@@ -195,6 +193,11 @@
195193
this.originValid = undefined
196194
}
197195
},
196+
syncValidatorValue() {
197+
this.pending = false
198+
this.validatorModel[this.validatorModelKey] = this.modelValue
199+
this.form.updatePending()
200+
},
198201
validatorChangeHandler() {
199202
// disabled or true to true no update validity
200203
if (this.validatorDisabled || (this.originValid && this.lastOriginValid)) {

src/components/form/form.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
dispatchEvent(this.$refs.form, 'reset')
125125
},
126126
submitHandler(e) {
127+
// sync all fields value because trigger: blur
128+
this.syncValidatorValues()
127129
if (this.skipValidate) {
128130
this.$emit(EVENT_SUBMIT, e, this.model)
129131
return
@@ -169,6 +171,11 @@
169171
this.setValidating()
170172
this.setPending()
171173
},
174+
syncValidatorValues() {
175+
this.fields.forEach((fieldComponent) => {
176+
fieldComponent.syncValidatorValue()
177+
})
178+
},
172179
validate(cb) {
173180
const promise = cb2PromiseWithResolve(cb)
174181
if (promise) {

0 commit comments

Comments
 (0)