Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export function ArrayField({
// the form state changes.
const watch = useWatch({ control });

const arrayValue = "json" in field.value ? field.value.json : field.value;

function getValueFromWatch() {
let r = watch;
for (const p of [ROOT_VALS_PROPERTY_NAME].concat(
Expand All @@ -48,13 +50,17 @@ export function ArrayField({

function onAddClick() {
setTextFieldKeys((old) => old.concat([`${currentKeyCount++}`]));
const watchValue = getValueFromWatch();
const arrayValue = "json" in watchValue ? watchValue.json : watchValue;
field.onChange(
getValueFromWatch().concat([defaultFormValuesForNode(node.childType)]),
arrayValue.concat([defaultFormValuesForNode(node.childType)]),
);
}

function onDeleteClick(index: number) {
const newArr = [...getValueFromWatch()];
const watchValue = getValueFromWatch();
const arrayValue = "json" in watchValue ? watchValue.json : watchValue;
const newArr = [...arrayValue];
const newKeysArr = [...textFieldKeys];
newArr.splice(index, 1);
newKeysArr.splice(index, 1);
Expand All @@ -66,7 +72,7 @@ export function ArrayField({
iconElement={<DataArray className="mr-1" />}
title={label}
>
{field.value.map((parsedNode: ParsedInputNode, i: number) => (
{arrayValue.map((parsedNode: ParsedInputNode, i: number) => (
<span
key={`${JSON.stringify(parsedNode)} ${i}`}
className="flex flex-row items-start"
Expand Down