fields producing boolean values (radios or switch components) always invalid when `false`
See original GitHub issueDescribe the bug
on a field that has required: true
, setting a boolean value makes the field valid only when is true
(and invalid when it’s false
)
Expected behavior
the field should be invalid only when the value is null || undefined
, if it is either true || false
it’s a valid boolean value
Culprit of this behaviour is this line:
https://github.com/react-hook-form/react-hook-form/blob/master/src/logic/validateField.ts#L80
It states that “if a value is boolean, must be True, otherwise it is invalid”
Why is this behaviour in place?
Using version: 5.7.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
What am I misunderstanding in my boolean radio group in ...
The problem is described here Radio values must be strings, can't be numbers or booleans and as I see it's not solved 'from...
Read more >invalid - CSS: Cascading Style Sheets - MDN Web Docs
The :invalid CSS pseudo-class represents any , , or other element whose contents fail to validate.
Read more >Final Form Docs – `FieldProps`
A function that takes the field value, all the values of the form and the meta data about the field and returns an...
Read more >Considerations for Using Flows in the Field Service Mobile App
Creating a Choice Option. If the user selects the choice value to use in a screen component, such as a radio button or...
Read more >Problem with Radio buttons for a boolean field on
The form works in a testing mode, but when published to SharePoint, the value is blank. All settings look like they are set...
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
It has to be something like
I’d suggest to simply provide a default radio / switch value, as these input controls are not designed to contain an
undefined
valueI overcome this issue by doing validations using validate function in rules