-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
issue: Controlled inputs initiated with null don't get reset #7590
Comments
cc @msageryd |
You need to provide a string to the input if you want it to use in a controlled mode. This is not related to react-hook-form but to react (you can see the warning in the console). So when you call reset in your example it's already in controlled mode and cannot be used with null/undefined: example |
thanks, @Moshyfawn & @Evalon that's correct. |
First of all, you're completely right. I got stuck thinking about the "not Also, the Is it a good idea to update the controller docs notes to mention
|
@Moshyfawn i will update it now. |
updated: react-hook-form/documentation@ac4caef deploying |
@bluebill1049 I think it's should be possible that defaultValues contains null for more complex cases (select or some custom controls). Just text inputs cannot be used with null. |
correct @Evalon hmmm how can I word it better... |
this is what i going with
|
thank you guys 🙏 closing this issue. |
Thanks for the clarification. I will try to adopt to this. On a side note, React-Native seems capable of handling null as field values. I am now initializing the form with a default object where all fields are set to null. When I call I guess that I should not rely on this if I want to use my form engine with web components going forward. Edit: https://snack.expo.dev/@msageryd/rhf-reset-example edit again: |
@bluebill1049 How would you deal with a situation where the controlled field doesn't accept an empty string as a value? I'm trying reset the value of a Prime Calendar component and setting the value to a string results in the following error: |
Version Number
7.24.1
Codesandbox/Expo snack
https://codesandbox.io/s/reset-controlled-example-forked-q62kd?file=/src/App.tsx
Steps to reproduce
Expected behaviour
Controlled inputs get properly reset with it's default set to
string
ornull
as per this comment and RHF docs on controlled inputsSee #7589 for context
What browsers are you seeing the problem on?
Firefox, Chrome, Safari, Edge
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: