Warn from SchemaField, for every type, when an enum hides anyOf/oneOf titles or ui:enumNames is ignored beside constant options
Prerequisites
- I have read the documentation
What theme are you using?
core
Is your feature request related to a problem? Please describe.
Follow-up from #5364 (#5319), raised in review (r4131579117).
#5364 added two development warnings (logOnce(), naming the field), but only BooleanField logs them. Every other type drops the same configuration silently:
An
enumbeside a non-constantanyOf/oneOfhides the option titles.SchemaField'sisConstantSelect()treats theenumas a select, so theanyOf/oneOftitles never render. The options are read from theenum, not theanyOf/oneOf.{ "type": "string", "enum": ["a", "b"], "oneOf": [{ "title": "A" }, { "title": "B" }] }This renders
['', 'a', 'b']with no warning. The boolean spelling warns.ui:enumNames/ui:enumOrderbeside constantanyOf/oneOfoptions are ignored.optionsList()applies them only toenumvalues.{ "type": "string", "oneOf": [{ "const": "a" }, { "const": "b" }] }With
{ "ui:enumNames": ["A", "B"] }, this rendersa/bwith no warning. The boolean spelling warns.
Describe the solution you'd like
Move both checks from BooleanField into SchemaField, which already decides whether a schema is a select (getSelectSchemaInfo()/isConstantSelect()) and already logs uiSchema misconfiguration through logOnce() and fieldLabelForLog(). Then every type warns the same way, and BooleanField stops carrying its own copy.
The boolean conditions to carry over:
- Hidden titles: some option has a
titleor aui:titleinuiSchema.anyOf/uiSchema.oneOf(hasOptionLabels(), already shared by both files), and someenumvalue isn't named byui:enumNames. - Ignored
ui:enumNames/ui:enumOrder: a non-emptyui:enumNames, or aui:enumOrderthat would reorder or drop one of the constant options, beside constant options. - When to skip: any widget other than the registered
SelectWidget/RadioWidget, such as a checkbox, a hidden field or a custom widget like daisyui'stoggle, which may show no option labels. A boolean checkbox thatSchemaFieldonly defaulted to still warns about ignored names when there are several options, since the names were meant to label a select.
Read the inference decision, don't re-derive it
BooleanField currently decides that a checkbox is one SchemaField defaulted to by checking !widget && altSchemas.length > 1 after the fact, which duplicates inferSelectWidget()'s criteria and can drift from them (raised in review, r4149888053). Moving the check next to inferSelectWidget() should use its actual decision instead.
A case that shows the drift, to cover with a test: SchemaField skips widget inference when a ui:field other than fields.BooleanField is set. So a custom field that wraps BooleanField:
const MyBool = (props) => <BooleanField {...props} />;with { "ui:field": "MyBool", "ui:enumNames": ["Accept", "Decline"] } on
{ "type": "boolean", "oneOf": [{ "const": true, "title": "Yes please" }, { "const": false, "title": "No thanks" }] }gets no inferred widget, renders a checkbox, and logs "Label those options with a title or a ui:title", even though the options are already titled.
Describe alternatives you've considered
- Warn from
optionsList(). It can't name the field or see the widget, and it's also called outside rendering (for example bygetDefaultFormState()). - Leave the warnings boolean-only, as #5364 does. The same mistake then behaves differently depending on the field's
type.
Generated with Claude Code
Source: rjsf-team/react-jsonschema-form