react-final-form
react-final-form copied to clipboard
reset data of a field
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,
}
// ...