final-form / final-form/react-final-form
resetFieldState breaking hard on not-yet mounted fields
- Dominant language
- JavaScript
- Stars
- 7.4k
- Forks
- 497
- PR merge metrics
- No merged PRs in 30d
Description
### Are 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 ()
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 on `category` field
* clearing any selections in `subcategory` field when the user change `category`
* resetting the state of `subcategory` field (to hide any validation errors or messages)
Contributor guide
Assessment
This issue has not been assessed yet.