1
0
Fork 0
mirror of synced 2024-07-03 05:20:32 +12:00

Fix form validation exiting early

This commit is contained in:
Andrew Kingston 2021-08-19 14:02:03 +01:00
parent c3cf48c268
commit 7d4a656ce2

View file

@ -118,24 +118,21 @@
return fieldInfo
},
validate: (onlyCurrentStep = false) => {
// Validate only the current step if required
let valid = true
let validationFields = fields
// Reduce fields to only the current step if required
if (onlyCurrentStep) {
const stepFields = fields.filter(f => get(f).step === get(currentStep))
for (let field of stepFields) {
if (!get(field).fieldApi.validate()) {
return false
}
}
return true
validationFields = fields.filter(f => get(f).step === get(currentStep))
}
// Otherwise validate all fields
for (let field of fields) {
// Validate fields and check if any are invalid
validationFields.forEach(field => {
if (!get(field).fieldApi.validate()) {
return false
valid = false
}
}
return true
})
return valid
},
clear: () => {
// Clear the form by clearing each individual field