Fix #317: Clear field modified flag after reset/initialize#536
Conversation
When reset() or initialize() is called, the modified flag on fields wasn't being updated to reflect the new initialValues. Fix: After updating initialValues, recalculate the modified flag for each field by comparing current value with new initial value. Added tests verifying: - reset() clears modified flag - initialize() clears modified flag when value matches new initial value
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis PR adds two test files documenting FinalForm's field modified flag behavior during reset and async validation scenarios, and implements a fix in FinalForm.ts that recomputes each field's modified flag by comparing current values to initial values using the field's isEqual method after reinitialization. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
The fix to recalculate modified flags after initialize adds ~26 bytes. Small size increase is acceptable for fixing the bug.
|
Published in |
Problem: When
reset()orinitialize()is called, themodifiedflag on fields staystrueeven though the field value now matches the new initial value.Root Cause: The
initialize()function updatesformState.initialValuesandformState.values, but doesn't recalculate themodifiedflag for existing fields.Solution: After updating initial values, loop through all fields and recalculate their
modifiedflag by comparing current value with new initial value:modified = falsekeepDirtyOnReinitialize) →modified = trueTesting:
Fixes #317
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests