From 12496de094451472fee5c5448bb479ae430cca58 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Thu, 5 Dec 2024 16:04:07 +0100 Subject: [PATCH] account for expandable checklists in validation --- .../src/@planx/components/Checklist/Editor/Editor.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/editor.planx.uk/src/@planx/components/Checklist/Editor/Editor.tsx b/editor.planx.uk/src/@planx/components/Checklist/Editor/Editor.tsx index 49c592a064..2fcc03c3de 100644 --- a/editor.planx.uk/src/@planx/components/Checklist/Editor/Editor.tsx +++ b/editor.planx.uk/src/@planx/components/Checklist/Editor/Editor.tsx @@ -72,8 +72,11 @@ export const ChecklistComponent: React.FC = (props) => { alert(JSON.stringify({ type, ...values, options }, null, 2)); } }, - validate: ({ options, ...values }) => { + validate: ({ options, groupedOptions, ...values }) => { const errors: FormikErrors = {}; + // Account for flat or expandable Checklist options + options = + options || groupedOptions?.map((group) => group.children)?.flat(); if (values.fn && !options?.some((option) => option.data.val)) { errors.fn = "At least one option must set a data value when the checklist has a data field";