Provide an element that converts large radio/checkbox option to select list

Created on 19 February 2022, over 2 years ago
Updated 3 March 2023, over 1 year ago

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:

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

Data model changes

Release notes snippet

Feature request
Status

Needs work

Version

10.0

Component
Form 

Last updated about 8 hours ago

Created by

🇺🇸United States mglaman WI, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024