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

reset data of a field

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

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.