Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultValue for SelectArrayInput inside ArrayInput -> SimpleFormIterator -> FormDataConsumer is not applied #9188

Closed
ghost91- opened this issue Aug 16, 2023 · 2 comments · Fixed by #9198
Labels

Comments

@ghost91-
Copy link

ghost91- commented Aug 16, 2023

What you were expecting:
When using a SelectArrayInput inside ArrayInput -> SimpleFormIterator -> FormDataConsumer, when removing an element from the ArrayInput (either by clicking the "Remove" button or the "Clear the list" button), and then adding a new element, the defaultValue for the SelectArrayInput is used for the new element.

What happened instead:
When doing the above, the SelectArrayInput of the new element is empty.

The underlying reason seems to be that the property for the SelectArrayInput is being set to null instead of removing it from the record, for some reason. SelectArrayInput has some special handling to ensure that the value always is an array, but it simply falls back to the empty array in this case. We ran into this problem with a custom component that works similar to SelectArrayInput, but didn't catch this, so our component actually crashed, because it received "" as value, instead of an array (the null seems to be converted to "" by the useInput hook).

Steps to reproduce:

  • Open https://stackblitz.com/edit/github-5j4apk
  • Got to the comment list and edit the single existing comment
  • Click the "Remove" button for the single existing item in the ArrayInput labeled "Items".
  • Click the "Add" button
  • Observe that nothing is selected in the "data" SelectArrayInput (while it should have "Foo" selected).

Environment

  • React-admin version: 4.13.0
  • React version: 17/18
  • Browser: Firefox/Chromium
@djhi
Copy link
Contributor

djhi commented Aug 17, 2023

Reproduced, thanks

@ghost91-
Copy link
Author

Thanks for fixing this so quickly! I'm always amazed with how quickly you react to bug reports! Big props to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants