A boolean field labels its enum values and empty-titled constants differently
Detect
- In your schema:
"type": "boolean"with anenumsuch as[true]or[true, false, null], and noui:enumNamesnaming its values. - In your schema: a boolean constant option with
"title": "". - On the rendered page, in tests or snapshots: that field's options read Yes, No and
nullwhere they readtrue,falseandnull, or an empty label where they read Yes or No. - In a custom widget:
options.enumOptionslabels areYes/Noinstead oftrue/false.
Change
A type: 'boolean' field labels every true and false in its enum that ui:enumNames doesn't name with the translated Yes/No, as it already labelled untitled boolean constants (#5319). Only an unnamed two-value enum of true and false read Yes/No before. The labels are in the enumOptions passed to whatever widget renders the field, so a select, radios or a custom widget reading options.enumOptions shows them.
A constant option whose title is "" now has an empty label, since BooleanField reads its options through optionsList(), which keeps an empty title for every other type (#4448). Drop the empty title to keep Yes or No.
To keep other labels, name the values:
const uiSchema = {
agree: {
+ 'ui:enumNames': ['true', 'false', 'null'],
},
};
ui:enumOrder now applies to these options too; see ui:enumOrder now orders boolean options.
Verify
- The options read the labels you named, or Yes/No in the form's language.
- Tests and snapshots that matched
true/falseoption text are updated and pass.
Also read: