Skip to content

Commit

Permalink
Introduce buildValue function for RepeatableGroups
Browse files Browse the repository at this point in the history
  • Loading branch information
ir4y committed Nov 27, 2024
1 parent aa704bd commit 6a35ed7
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import s from './RepeatableGroups.module.scss';
interface RepeatableGroupsProps {
groupItem: GroupItemProps;
renderGroup?: (props: RepeatableGroupProps) => ReactNode;
buildValue?: (value:any) => any;
}

function defaultBuildValue() {
return {};
}

export function RepeatableGroups(props: RepeatableGroupsProps) {
Expand All @@ -22,6 +27,7 @@ export function RepeatableGroups(props: RepeatableGroupsProps) {
const fieldName = [...parentPath, linkId];
const { value, onChange } = useFieldController(fieldName, questionItem);
const items = value.items && value.items.length ? value.items : required ? [{}] : [];
const buildValue = props.buildValue ?? defaultBuildValue;

return (
<div className={s.group}>
Expand Down Expand Up @@ -57,7 +63,7 @@ export function RepeatableGroups(props: RepeatableGroupsProps) {
className={s.addButton}
onClick={() => {
const existingItems = items || [];
const updatedInput = { items: [...existingItems, {}] };
const updatedInput = { items: [...existingItems, buildValue(value)] };
onChange(updatedInput);
}}
size="small"
Expand Down

0 comments on commit 6a35ed7

Please sign in to comment.