Skip to content

Commit

Permalink
buildValue has full controll over repeatable group values
Browse files Browse the repository at this point in the history
  • Loading branch information
ir4y committed Nov 27, 2024
1 parent 6a35ed7 commit eb71d59
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>, value:any) => any;
}

function defaultBuildValue() {
return {};
function defaultBuildValue(exisingItems:Array<any>, _value:any) {
return [...exisingItems, {}];
}

export function RepeatableGroups(props: RepeatableGroupsProps) {
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit eb71d59

Please sign in to comment.