A required checkbox group, multiple select, file input or array widget needs minItems to show as required
Detect
- A property listed in
requiredin your schema whose array renders as one widget, with nominItemsof at least 1: a group of checkboxes (ui:widget: 'checkboxes'), a<select multiple>(an array ofenumvalues), a file input (items offormat: 'data-url') or a custom array widget. - On the rendered page, that field lost its
*, its control is no longerrequired, and submitting it empty now callsonSubmitwith[]. - A test that finds a required group by name, such as
getByRole('group', { name: 'Colors' }). - A custom checkboxes widget in your code that calls
getGroupAttributes(), or@rjsf/daisyui'sgetGroupAndOptionProps(). - A custom array widget in your code that assumes it is required.
Change
A required array rendered as one widget is required, by its * and the required its widget is handed, only where its schema demands an item with a minItems of at least 1, or where ui:required: true asks for it (#5573, #5744). getDefaultFormState() seeds a required array with [], which required alone accepts. The form already submitted [] for a group with nothing checked, and a <select multiple>'s native required had the browser block that submit, so the form called neither onSubmit nor onError. Add minItems: 1 to keep the * and required, which also has the form report an empty selection:
colors: {
type: 'array',
items: { type: 'string', enum: ['red', 'green'] },
uniqueItems: true,
+ minItems: 1,
},
-
A required group's accessible name then ends in "required" (
TranslatableString.RequiredGroupCue), so a test finding it by name expects that. A customtranslateStringhandles the new key; see A translateString that maps every key needs the new TranslatableString keys.- getByRole('group', { name: 'Colors' });+ getByRole('group', { name: 'Colors required' }); -
A custom checkboxes widget calling
getGroupAttributes()passes theregistryand renders therequiredCueit returns, or its name stays as it was. So does one calling@rjsf/daisyui'sgetGroupAndOptionProps(), which takes theregistryand returns therequiredCuealike, whilegetGroupProps()returns no cue. -
A custom array widget reads its
requiredprop instead of assuming one. -
Only
minItemsandui:requiredare read. A required group with nominItemsshows no*or cue even where acontainsrejects[], so the form blocks that submit; give such a groupminItems: 1orui:required: true. -
An array holding no value, as
emptyObjectFields: 'skipEmptyDefaults'leaves it, stays required and keeps its*and cue, since the form rejects that. -
An
anyOf/oneOffield follows the option shown: a required field shows no*while that option holds the[]of such a group or thefalseof a checkbox whose schema accepts it. -
An array rendered as a list of items keeps its
*.
Verify
- With
minItems: 1, the field shows its*, a group's name ends in "required", and submitting it empty callsonErrorwith aminItemserror. - Without it, the field shows no
*and submitting it empty callsonSubmitwith[].
Also read: