question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting defaultValue to null on DatePicker wrapped by Controller turns "isValid" to false

See original GitHub issue

Describe the bug Using “defaultValue” = null on a DateField wrapped in Controller turns “isValid” in formState to “false”.

To Reproduce

  1. Open attached CodeSandbox
  2. Submit button is disabled because “isValid” is false
  3. Change defaultValue={null} on second Field to defaultValue={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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
MrBlue9commented, Jun 5, 2020

Oh, now I see it! My ternary operators for both validations on that field are messed up! I got it working now! Thank you!

0reactions
MrBlue9commented, Jun 5, 2020

Should “isValid” not be true and the form therefore submittable because the field “date of birth” is not required?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found