Setting defaultValue to null on DatePicker wrapped by Controller turns "isValid" to false
See original GitHub issueDescribe the bug Using “defaultValue” = null on a DateField wrapped in Controller turns “isValid” in formState to “false”.
To Reproduce
- Open attached CodeSandbox
- Submit button is disabled because “isValid” is false
- Change
defaultValue={null}
on second Field todefaultValue={new Date()}
and Submit button is not disabled anymore when loading form again
Codesandbox link (Required) https://codesandbox.io/s/gallant-jang-cqm4d?file=/src/App.tsx
Expected behavior One should be able to initialize the field without a preset Date.
Additional context I can’t wrap my head around if this is an issue with the MUI DatePicker or with react-hook-form itself. Because the “date of birth” field in my CSB should be optional, it should also be initialized without a value. But even after entering a value, isValid stays false.
Maybe someone can have a look at my CSB example and figure out what I’m doing wrong, because I tried so much but can’t get it right somehow 😦
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
SwiftUI DatePicker Binding optional Date, valid nil
The default value is noSegment (no segment selected) until the user touches a segment. Set this property to -1 to turn off the...
Read more >Set Datepicker to null / empty throws error? - MDBootstrap
Actual behavior Setting defaultvalue to empty string or null results in an error in the dev console. valueDefault=' ' or valueDefault=null Resources ( ......
Read more >Solved: DatePicker empty value - Power Platform Community
Solved: Have been playing some more with the DatePicker in an EditForm, but can't seem to work out how to ensure a blank...
Read more >Date Picker - DriveWorks Pro Help
The Date Picker is a form control that allows a date to be selected from an interactive calendar. The Date Picker appears on...
Read more >View - Android Developers
android:saveEnabled, If false, no state will be saved for this view when it is being ... If not set, the default value will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh, now I see it! My ternary operators for both validations on that field are messed up! I got it working now! Thank you!
Should “isValid” not be true and the form therefore submittable because the field “date of birth” is not required?