A boolean with labelled constant options renders a select instead of a checkbox
Detect
- In your schema: a
type: 'boolean'whoseoneOf/anyOfhas more than one constant option, at least one labelled by itstitleor by aui:titlein the matchinguiSchema.oneOf/uiSchema.anyOfentry. - In your schema: a nullable boolean (
"type": ["boolean", "null"]) whose options include anullconstant, labelled or not. - On the rendered page or in snapshots: a select where the field rendered a checkbox.
Change
A checkbox shows no option labels, so such a boolean now defaults to a select, the same widget its typeless spelling gets (#5309):
{
"type": "boolean",
"oneOf": [
{ "const": true, "title": "Yes" },
{ "const": false, "title": "No" }
]
}
A nullable boolean with a null constant gets the select too, since a checkbox has no state for null. A single option, the usual way to spell a checkbox that must be checked, and unlabelled true/false options keep the checkbox.
A custom field chosen by ui:field isn't handed that default: its uiSchema has no ui:widget unless the caller set one. ui:field: 'BooleanField' still gets the select, and so does a field registered under the schema's $id.
To keep the checkbox:
const uiSchema = {
- agree: {},
+ agree: { 'ui:widget': 'checkbox' },
};
Verify
- The field renders the widget you chose, and updated snapshots show the select where you kept it.
Also read: