You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suggestion: Add a shouldUnregister parameter to the form.getValues() method to work alongside useForm({ shouldUnregister: false }), improving the developer experience.
#12666
useForm withshouldUnregister can handle automatic clearing of data under linked logic, but it results in a poor user experience.
For example, I have four radio buttons A, B, and C that can toggle types, each associated with different fields.
When shouldUnregister = true, if the user fills in the fields under type A and then switches to type B, returning to type A results in the previously filled data being completely cleared, which is very unfriendly to the user.
When shouldUnregister = false, this problem can be resolved, but if users fill in data for both types A and B, when submitting the form, while using form.getValues(), the data will include dirty data from type B since type A is the final submission, requiring developers to manually clear this. This is also unfriendly for developers since the UI logic needs to reprocess the data upon submission, which is prone to errors.
Is it possible to provide a new parametershouldUnregister to the getValues function? This would allow users to obtain clean form data by calling form.getValues(shouldUnregister), automatically excluding hidden data.
In other words, when shouldUnregister = false, it ensures a good user experience for UI editing. When retrieving data, by using form.getValues({ shouldUnregister: true }), it only fetches the data from registered fields, ensuring the accuracy of the submitted data.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
dev confusion
useForm
withshouldUnregister
can handle automatic clearing of data under linked logic, but it results in a poor user experience.For example, I have four radio buttons A, B, and C that can toggle types, each associated with different fields.
When
shouldUnregister = true
, if the user fills in the fields under type A and then switches to type B, returning to type A results in the previously filled data being completely cleared, which is very unfriendly to the user.When
shouldUnregister = false
, this problem can be resolved, but if users fill in data for both types A and B, when submitting the form, while using form.getValues(), the data will include dirty data from type B since type A is the final submission, requiring developers to manually clear this. This is also unfriendly for developers since the UI logic needs to reprocess the data upon submission, which is prone to errors.Expected behaviour & Suggestion
Is it possible to provide a new parameter
shouldUnregister
to thegetValues
function? This would allow users to obtain clean form data by callingform.getValues(shouldUnregister)
, automatically excluding hidden data.In other words, when
shouldUnregister = false
, it ensures a good user experience for UI editing. When retrieving data, by usingform.getValues({ shouldUnregister: true })
, it only fetches the data from registered fields, ensuring the accuracy of the submitted data.API like
Beta Was this translation helpful? Give feedback.
All reactions