Closed vidur149 closed 5 years ago
I second your opinion on the expected behaviour, <Field .. initialValue={..}
should allow for a non-resetting initialValue
experience as does the initialValues
on the form level.
Try using initialValues
on the entire form instead of on the field level. If that is not possible, you may take a look at this intermediate workaround by @Andarist https://github.com/final-form/react-final-form/issues/533#issuecomment-502343047 using hooks.
@ndrsllwngr I can use the hooks solution because I am using classes in my react component. I will have to rewrite the entire thing and learn hooks. :/
You should be able to implement similar logic based on FormSpy
using double render technique - render null at first just to get access to the form object from FormSpy and setState to render the desired component.
@Andarist can you please elaborate on this?
@Andarist I tried many hacks with FormSpy, not able to make even a single one work. Help would be appreciated, as we are using react-final-forms in couple of places and I love using the library.
Somehow, the initialValue seems to cause a trouble in other cases as well. Like in other place if I set field level initialValue(x
) for a field A
and change its value from x
to y
, and then I make some changes to underlying fields, field A
takes back the x
value. This is very weird behaviour for me.
@erikras can you help?
Fix published in final-form@4.18.6
.
bug report
What is the current behavior?
I am using wizrard form. The form in total has three pages. On the basis of field values of the first page, second page field values are generated from an API request. We are sending some default values from our backend and I am setting the initialValue for the field. Everything works fine for the first time but as soon as I navigate to third page and come back to the second page, whatever change I have made to the field values are lost and the fields take up the initial values.
What is the expected behavior?
The field should retain the changed values.
Second page fields
What's your environment?
🏁 React Final Form version 6.1.0 🏁 Final Form version 4.13.1 OS/browser affected Mojave/Chrome React 16.8.6