A required boolean, a checkbox and validation
See original GitHub issueNot 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:
 - Created 8 years ago
 - Comments:7 (1 by maintainers)
 
Top 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 >
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

checkbox{
type: ‘boolean’, default: null, enum: [null, true], }
You are a genius!!