Browse Source

Fix form validation exiting early

pull/4023/head
Andrew Kingston 5 years ago
parent
commit
7d4a656ce2
  1. 23
      packages/standard-components/src/forms/InnerForm.svelte

23
packages/standard-components/src/forms/InnerForm.svelte

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

Loading…
Cancel
Save