final-form / final-form/react-final-form
reset data of a field
- Dominant language
- JavaScript
- Stars
- 7.4k
- Forks
- 497
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
I try to reset a field to its initial data, so at the moment I am using:
```js
form.change('nameOfField', form.getFieldState('nameOfField').initial);
```
this works but if you do not use a field in your form, `getFieldState('nameOfField')` is undefined.
In my case it is undefined because some of my form elements are conditionally rendered only if I pick something in the form, so nothing listen to some field, if the condition is not true.
Is there another way to get the initial/raw data of the form anyway?
one idea is to use the data you inject to your form or extend your initial data like this:
```js
// ...
initialValues: {
...data,
initialProducts: data.products,
initalUsers: data.users,
}
// ...
```
Contributor guide
Assessment
This issue has not been assessed yet.