From eb71d593dfc484adf37c70e296fc3e82779230a7 Mon Sep 17 00:00:00 2001 From: Ilya Beda Date: Wed, 27 Nov 2024 12:38:14 +1100 Subject: [PATCH] buildValue has full controll over repeatable group values --- .../widgets/Group/RepeatableGroups/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/BaseQuestionnaireResponseForm/widgets/Group/RepeatableGroups/index.tsx b/src/components/BaseQuestionnaireResponseForm/widgets/Group/RepeatableGroups/index.tsx index 532357cf..bae7cf20 100644 --- a/src/components/BaseQuestionnaireResponseForm/widgets/Group/RepeatableGroups/index.tsx +++ b/src/components/BaseQuestionnaireResponseForm/widgets/Group/RepeatableGroups/index.tsx @@ -13,11 +13,11 @@ import s from './RepeatableGroups.module.scss'; interface RepeatableGroupsProps { groupItem: GroupItemProps; renderGroup?: (props: RepeatableGroupProps) => ReactNode; - buildValue?: (value:any) => any; + buildValue?: (existingItems:Array, value:any) => any; } -function defaultBuildValue() { - return {}; +function defaultBuildValue(exisingItems:Array, _value:any) { + return [...exisingItems, {}]; } export function RepeatableGroups(props: RepeatableGroupsProps) { @@ -63,7 +63,7 @@ export function RepeatableGroups(props: RepeatableGroupsProps) { className={s.addButton} onClick={() => { const existingItems = items || []; - const updatedInput = { items: [...existingItems, buildValue(value)] }; + const updatedInput = { items: buildValue(existingItems, value) }; onChange(updatedInput); }} size="small"