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.

fields producing boolean values (radios or switch components) always invalid when `false`

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Moshyfawncommented, Apr 21, 2022

@hemadriDasari1990 can you please share your solution?

It has to be something like

validate: (value) => {
  if (value == null) {
    return "Please, choose a value"
  }
  return true
}

I’d suggest to simply provide a default radio / switch value, as these input controls are not designed to contain an undefined value

2reactions
hemadriDasari1990commented, Jul 27, 2020

I overcome this issue by doing validations using validate function in rules

Read more comments on GitHub >

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

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