Skip to content

[Fix] Prevent stale nested field values when re-adding items in SimpleFormIterator#11201

Merged
ThieryMichel merged 2 commits intomasterfrom
fix-simpleformiterator-nested-defaults
Mar 26, 2026
Merged

[Fix] Prevent stale nested field values when re-adding items in SimpleFormIterator#11201
ThieryMichel merged 2 commits intomasterfrom
fix-simpleformiterator-nested-defaults

Conversation

@WiXSL
Copy link
Copy Markdown
Collaborator

@WiXSL WiXSL commented Mar 25, 2026

Problem

SimpleFormIterator reused values from a removed item when adding a new one back, for nested fields.

Solution

  • Create proper default values for nested fields when adding a new item
  • Read iterator row values from the current form state so removed items are not reused

How To Test

1- Open a form with an ArrayInput
2- Use nested sources
3- Remove an item
4- Add a new item
5- Verify the new row is empty and does not reuse the removed values

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)

@WiXSL WiXSL added the RFR Ready For Review label Mar 25, 2026
@WiXSL WiXSL changed the title [Fix] Nested defaults in SimpleFormIterator Fix stale nested field values when re-adding items in SimpleFormIterator Mar 25, 2026
@WiXSL WiXSL changed the title Fix stale nested field values when re-adding items in SimpleFormIterator [Fix] Prevent stale nested field values when re-adding items in SimpleFormIterator Mar 25, 2026
const records =
useWatch({
name: finalSource,
}) ?? get(record, finalSource);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you need this ? It adds extra rerenders, and removing it do not break any tests, nor does it reintroduce the bug.
The fix in SimpleFormInterator seems sufficient.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You are right! Based on my earlier testing, I thought this change was needed. I re-ran the tests now and the fix still works without it, so we can avoid those extra re-renders.

@ThieryMichel ThieryMichel added this to the 5.14.5 milestone Mar 26, 2026
@ThieryMichel ThieryMichel merged commit 2644a67 into master Mar 26, 2026
15 checks passed
@ThieryMichel ThieryMichel deleted the fix-simpleformiterator-nested-defaults branch March 26, 2026 14:44
@ThieryMichel ThieryMichel mentioned this pull request Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants