Repository navigation
Fix: Prevent reset of controlled form fields after form actionFix: Prevent reset of controlled form fields after form actionfeat: Add controlled field detection for form reset functionalityAdd … - #34295
Closed
DHANUSHRAJA22 wants to merge 1 commit into
Conversation
…controlled field detection for form reset functionalityAdd controlled field detection for form reset functionalityUpdate ReactDOMFormActions.js This commit enhances the form reset functionality in ReactDOMFormActions.js by: 1. Added isControlledField() helper function that detects if a form field is controlled (has value or checked props from React) 2. Added resetFormFieldsAfterAction() function that resets form fields after successful form action with logic to: - Skip resetting controlled fields (preserving React state management) - Reset uncontrolled fields as before 3. Modified requestFormReset() to use the new controlled/uncontrolled detection logic 4. Exported helper functions for potential external use This ensures that controlled components maintain their state while uncontrolled components are properly reset after form actions.
|
I tested this change with forms that mix controlled and uncontrolled fields |
7 tasks done
|
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
|
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #30580. Ensures only uncontrolled
<input>,<select>, and<textarea>fields are reset after form action. Controlled fields (with value or checked props) are skipped. Includes helper and dev logging.Summary
This PR addresses issue #30580 by implementing controlled field detection in form reset functionality. The current implementation was resetting all form fields after a form action, which was causing controlled React components to lose their managed state.
What changed
isControlledField()helper function - Detects if a form field is controlled by checking for React props (value or checked)resetFormFieldsAfterAction()function - Resets only uncontrolled fields while preserving controlled field staterequestFormReset()- Now uses the new controlled/uncontrolled detection logicHow it works
The solution examines each form element's React fiber node to determine if it has controlled props:
<input>elements: checks forvalueprop (text inputs) orcheckedprop (checkboxes/radio)<textarea>and<select>elements: checks forvaluepropTesting
Tested with forms containing both controlled and uncontrolled components. Verified that:
This commit enhances the form reset functionality in ReactDOMFormActions.js by:
This ensures that controlled components maintain their state while uncontrolled components are properly reset after form actions.
Summary
How did you test this change?