react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

reset data of a field

Open codelover2k opened this issue 4 years ago • 0 comments

Hi!

I try to reset a field to its initial data, so at the moment I am using:

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:

// ...
initialValues: {
  ...data,
  initialProducts: data.products,
  initalUsers: data.users,
}
// ...

codelover2k avatar Nov 22 '21 15:11 codelover2k