Problem/Motivation
In the current UI a user can add a huge number of options in a list, and choose either a Select Box or Radio buttons regardless of it's UX.
User interface guidelines like from MS, Apple, Gnome etc give usually quite clear suggestions on this:
- Radio buttons: less than 5 choices
- Select Box: 6 to 10 options
- Scrollable list: 11 or more options or
See reference here.
Other sources:
- https://www.nngroup.com/articles/listbox-dropdown/
- https://uxpickle.com/dropdown-vs-radio-button-vs-checkboxes-which-one-to...
- https://joechiang.com/post/when-use-radio-buttons-select-dropdowns
Proposed resolution
6 years ago, Drupal Commerce added an element for entity references. It adapts to the available options: if there are 7 or more options, a select box is used instead.
https://git.drupalcode.org/project/commerce/-/blob/8.x-2.x/src/Element/E...
I remember bojanz researched and found 7 was a common pattern.
(@mglaman)
A lot of people building forms (either on the admin UI like node forms or final user forms like webforms or entity references) won't know this rule, or won't even be able to know how many items will be available when building the form. Providing an option that automatically converts large radio/checkbox option would improve usability.
Remaining tasks
User interface changes
A new form element "dynamic_options" has been added to address this feature request.
To make it available to end users a new widget declared in class Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsDynamicWidget
has been created.
This widget can be used used in both options and entity reference fields, like the existing "Select list" and "Check boxes/radio buttons" ones.
Site admins only need to configure the entity form mode like in the screenshot:
And then, the entity form dynamically would look like the one in the screenshot depending o nthe field and widget settings:
API changes
None
Data model changes
None