Skip to content

[Storybook] Fix <ArrayInputBase> story issue when adding back a removed item#11041

Merged
fzaninotto merged 1 commit intomasterfrom
fix-array-input-base-test-ui
Nov 13, 2025
Merged

[Storybook] Fix <ArrayInputBase> story issue when adding back a removed item#11041
fzaninotto merged 1 commit intomasterfrom
fix-array-input-base-test-ui

Conversation

@djhi
Copy link
Contributor

@djhi djhi commented Nov 13, 2025

Problem

When you remove an item from the <ArrayInputBase> and add another, the values from the previously added item are used.

Solution

This is because RHF requires that you provide values for a new item. As we can't know what inputs users will add, we have to actually inspect the SimpleFormIterator children to get their default values and use them for the new item. Until we have a better option, we extracted a hook to help with that.

How To Test

  • in the story
  • remove the last item
  • click add
    => you should have a new empty item

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature

@djhi djhi added the RFR Ready For Review label Nov 13, 2025
@fzaninotto fzaninotto merged commit c00616c into master Nov 13, 2025
15 checks passed
@fzaninotto fzaninotto deleted the fix-array-input-base-test-ui branch November 13, 2025 15:59
@fzaninotto fzaninotto added this to the 5.13.1 milestone Nov 13, 2025

return fields ? (
<SimpleFormIteratorBase {...props}>
<SimpleFormIteratorBase getItemDefaults={getItemDefaults} {...props}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably deserve an update to the https://marmelab.com/ra-core/simpleformiteratorbase/ docs

@slax57 slax57 changed the title Fix <ArrayInputBase> story issue when adding back a removed item [Storybook] Fix <ArrayInputBase> story issue when adding back a removed item Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

3 participants