How to update form values if select options change #10699
Unanswered
RamsayRomero
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'm rendering a form with two select elements like so: https://codesandbox.io/s/tender-archimedes-3ct6cj?file=/src/App.tsx
If I were to change the first select, the options for the second select will change. The value of the second select is now set to the first value of the new options, since the default value is not contained in the new options. However, when I submit the form the value of the second select is still the default value. I assume this is because the user never explicitly changed the select B option, so RHF doesn't know the value changed. I would prefer if it would pick up the value displayed in the browser, 'option6', since 'option3' can not technically be selected anymore. Is there some configuration I can use to make React Hook Form pick up the actual DOM element values on submit? Or would the only solution be to explicitly call
setValue
when the first select is changed?Beta Was this translation helpful? Give feedback.
All reactions