fix(components): [el-form]: ensure form validation always triggers callback (#3294)

ensures the callback is always called
This commit is contained in:
Robert Schönthal 2021-09-10 05:49:33 +02:00 committed by GitHub
parent 6db8dbca82
commit 509292678d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -184,7 +184,6 @@ export default defineComponent({
callback(true)
}
let valid = true
let count = 0
let invalidFields = {}
let firstInvalidFields
for (const field of fields) {
@ -194,11 +193,10 @@ export default defineComponent({
firstInvalidFields || (firstInvalidFields = field)
}
invalidFields = { ...invalidFields, ...field }
if (++count === fields.length) {
callback(valid, invalidFields)
}
})
}
callback(valid, invalidFields)
if (!valid && props.scrollToError) {
scrollToField(Object.keys(firstInvalidFields)[0])
}