final-form / final-form/react-final-form

resetFieldState breaking hard on not-yet mounted fields

Open
#621 13 comments 25 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.