From 7d4a656ce277c5f03bf9342c5ffb2030b5f5b96e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 19 Aug 2021 14:02:03 +0100 Subject: [PATCH] Fix form validation exiting early --- .../src/forms/InnerForm.svelte | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/standard-components/src/forms/InnerForm.svelte b/packages/standard-components/src/forms/InnerForm.svelte index ec5c066699..c8b76a7200 100644 --- a/packages/standard-components/src/forms/InnerForm.svelte +++ b/packages/standard-components/src/forms/InnerForm.svelte @@ -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