Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Reuse field states from already created instance #474

Open
Dragomir-Ivanov opened this issue Mar 3, 2023 · 5 comments
Open

Feature: Reuse field states from already created instance #474

Dragomir-Ivanov opened this issue Mar 3, 2023 · 5 comments

Comments

@Dragomir-Ivanov
Copy link
Contributor

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

@gertdreyer
Copy link
Collaborator

gertdreyer commented Apr 20, 2023

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.

@Dragomir-Ivanov
Copy link
Contributor Author

Thank you and sorry for the late response. I will make the mock-up and come back again.

@Dragomir-Ivanov
Copy link
Contributor Author

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!

@gertdreyer
Copy link
Collaborator

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.

@Dragomir-Ivanov
Copy link
Contributor Author

Hey @gertdreyer, any advice on this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants