Open k4v1cs opened 2 weeks ago
https://github.com/marmelab/react-admin/issues/9839 might be related or the same issue
Reproduced, thanks for the report.
It seems the issue disappears if you set shouldUnregister
on the <Form>
.
const TestEdit = () => {
return (
<Edit>
<SimpleForm shouldUnregister>
<Form />
</SimpleForm>
</Edit>
);
};
This can't be considered as a fix for the issue, but may be used as a workaround.
I tried to reproduce the issue in a RHF only sandbox, to see if the issue came from their code or ours, but couldn't reproduce the issue there (https://codesandbox.io/p/sandbox/calc-forked-hp97w7), which seems to indicate this affects react-admin only.
Also, I realize it is possible to set shouldUnregister
at the useFieldArray
level, so maybe this is something we should do in <ArrayInput>
. Not so sure about the impacts though...
What you were expecting: Removing an item form an ArrayInput should not cause validation errors on non-existent fields
What happened instead: After I removed the item and validated the form, there was a validation error for a no longer existing index
Steps to reproduce: Have an ArrayInput with items which also have ArrayInputs. The arrays as well as their items are validated as required. Codesandbox: https://codesandbox.io/p/devbox/nested-arrayinput-remove-item-issue-hz4yq8
The form is invalid, there is a validation error for the 4th item's nested array.
https://github.com/marmelab/react-admin/assets/4885562/839554e9-5159-4a56-b4c6-91453e9c40d9
Related code:
Other information: The issue is reproducible with version 5 as well: https://codesandbox.io/p/devbox/nested-arrayinput-remove-item-issue-forked-8shcyl
Environment