diff --git a/packages/dm-core-plugins/src/form/components/PrimitiveArray.tsx b/packages/dm-core-plugins/src/form/components/PrimitiveArray.tsx index 65e06cd45..198fc9997 100644 --- a/packages/dm-core-plugins/src/form/components/PrimitiveArray.tsx +++ b/packages/dm-core-plugins/src/form/components/PrimitiveArray.tsx @@ -7,6 +7,7 @@ import { DeleteSoftButton, TAttribute, } from '@development-framework/dm-core' +import { useFormContext } from 'react-hook-form' interface PrimitiveArrayProps { uiAttribute: TUiAttributeObject | undefined @@ -35,9 +36,10 @@ const PrimitiveArray = ({ onChange, }: PrimitiveArrayProps) => { const [hovering, setHovering] = useState(-1) + const methods = useFormContext() const updateValues = (index: number, newValue: TPrimitive): void => { - const newValues = [...data] + const newValues = [...methods.getValues(namePath)] switch (attribute.attributeType) { case 'boolean': newValues[index] = newValue @@ -53,7 +55,7 @@ const PrimitiveArray = ({ } } const removeItem = (index: number) => { - const newValues = [...data] + const newValues = [...methods.getValues(namePath)] newValues.splice(index, 1) onChange(newValues) }