resetFieldState breaking hard on not-yet mounted fields
See original GitHub issueAre you submitting a bug report or a feature request?
bug report
What is the current behavior?
Getting the following error when conditionally rendering and resetting a field (subcategory
) based on another field (category
)
Uncaught TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at getValidators (final-form.es.js:568)
at runFieldLevelValidation (final-form.es.js:581)
What is the expected behavior?
// Resets the subcategory to undefined
form.change("subcategory", undefined);
// Resets the field state
form.resetFieldState("subcategory");
to work whether or not the field subcategory
is mounted or not.
Sandbox Link
https://codesandbox.io/s/react-final-form-simple-example-7jt63
What’s your environment?
react 16.9.0 final-form 4.18.5 react-final-form 6.3.0
Other information
The expectations:
- show
subcategory
field only after the user make a selection oncategory
field - clearing any selections in
subcategory
field when the user changecategory
- resetting the state of
subcategory
field (to hide any validation errors or messages)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:11
Top Results From Across the Web
React Final Form reset form fields and validation but retain ...
I managed to achieve this by looping through all form posted values and resetting each individually: const submitForm = async (values, ...
Read more >mozilla-central: changeset 392810 ... - Mercurial
resetFieldStates (); + } + } + + // Unregister listeners once no field is in AUTO_FILLED state. + if (!this.hasFilledSection()) { +...
Read more >Final Form Docs – `FormApi`
Returns the state of a specific field, of type FieldState , as it was last reported to its listeners, or undefined if the...
Read more >useForm - reset - React Hook Form
Important: this keep option doesn't reflect form input values but only dirty fields form state. keepDirtyValues, boolean. DirtyFields and isDirty will remained, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 resetFieldState not working for me neither on a conditional field.
My use case is that when a “parent” field value changes I want to reset the state of the depending conditional fields like they had never been interacted with. In this case the conditional field might have never been or no longer be rendered; but it has been registered and so I would expect Final Form to imperatively perform operations on it.
This issue has been opened since Sept would be great to get a comment from maintainers so we know what we can expect.
resetFieldState
still doesn’t work