Feature: Reuse field states from already created instance
Greetings, Good to see that this project is still active.
Currently one can use createForm instance for the form, and then supply it to React with form={formDate}.
The issue is when fields unsibscribe, the form erases their FieldState. E.g. touched, valid, etc. However not always that is the right solution, especially with big forms, trying to hide parts of the form as optimization.
My wish is to add and option to each field, so FF can persist their FieldState on unsubscribe, and use it again when the same field subscribe.
I am willing to provide PRs, if my request makes sense to project owners.
Best, Dragomir
The use case does make sense, I have a feeling it is achievable already at this stage - have a look at wizards? If you can create a mock-up sandbox of a case where conditional rendering fails and discards the data we can have a look at it.
Thank you and sorry for the late response. I will make the mock-up and come back again.
Greetings @gertdreyer, Sorry for the delay. I have prepared the needed sandbox to demonstrate the issue. Please note, how field losses its state, when switching tabs.
https://stackblitz.com/edit/stackblitz-starters-vm3r9h?file=src%2FApp.tsx
Thanks again!
I have not debugged this behaviour properly but I feel it may be related to the code below when the field is not rendered anymore and touched becomes undefined.
https://github.com/final-form/final-form/blob/d20c44be8766b93424e7754fe2629820fd93d21a/src/FinalForm.js#LL616C1-L619C19
I would be willing to accept a PR for a new prop that enables the retaining of the meta state as long as it does not change the current default behaviour.
Hey @gertdreyer, any advice on this feature?