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.

A required boolean, a checkbox and validation

See original GitHub issue

Not sure if this is a bug or a feature, but if the schema requires a boolean value and this value is shown as a Checkbox, the validation always fails unless the box is checked.

I can see why it behaves like this, but my gut feeling says that when acheckbox is unchecked on a required boolean, the validation should pass and the value should be saved as false.

Work-around: show the boolean in the uiSchema as "ui:widget": "radio". This way you can explicitly choose the false value. Another possible (untested) work-around:

{
    "properties": {
        "some_flag": { "enum": [ true, false ] }
    }
}

But I think it should be the other way around: if it’s required (even when false), set it as required, it it has to be true, set "enum": [true] for the field.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ghostcommented, Nov 26, 2018

checkbox{
type: ‘boolean’, default: null, enum: [null, true], }

0reactions
SeanNexusVisacommented, Nov 15, 2022

checkbox{ type: ‘boolean’, default: null, enum: [null, true], }

You are a genius!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to validate a checkbox as boolean for a form submission
A checkbox is either its value or non-existent. That's the validation ;) And you know the value so no need to take it...
Read more >
JSF Required Checkbox using FacesValidator
When submitting the form, i.e. by pressing a button, the form is validated. If the checkbox is not checked, the RequiredCheckboxValidator will ...
Read more >
How to Validate Boolean/Checkbox MVC 3 - MSDN - Microsoft
First, I have a custom validation attribute called BooleanTrueAttribute. [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] ...
Read more >
JSF selectBooleanCheckbox required=true doesn't validate if ...
This seems like bug in jsf implementation, but when h:selectBooleanCheckbox is not checked, it's value is false and not empty or null ....
Read more >
CheckBox - It is impossible to validate a boolean property ...
Dear Support, I am once again being outfoxed by a validation issue. I have a checkbox in a form for acceptance of Terms...
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