reset not working as intended on switching edit mode form to view mode #12886
Unanswered
chumba-wamba
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am using react-hook-form to create a view/edit page. The page contains multiple sections which are collapsed by default. All of these sections are rendered within one
form
when edit mode is enabled to submit all the updated fields to the server in one shot.A server call is made on expanding a section to fetch the metadata aka names, labels, values, and the type of all the input fields associated with the section.
The
FieldRenderer
component is responsible for the view and edit mode of the field. It also conditionally renders a checkbox, input, etc. depending on thefieldType
(which is a part of thefield
object).I am initializing
useForm
without anydefaultValues
since its impossible to know them at compile time or via a server call due to the constraints of the application. Further, I am making use ofFormProvider
anduseFormContext
to pass methods fromuseForm
to all the children components.The edit mode works as expected but when I update some fields and try to reset the form on switching back to view mode (via a Cancel button), the form still reflects the changed values.
What should be the correct way to achieve the intended behavior, here?
Beta Was this translation helpful? Give feedback.
All reactions