Support grouping for checkboxes and radio buttons

Created on 11 August 2022, almost 2 years ago
Updated 22 April 2024, about 2 months ago

Problem/Motivation

Currently Drupal does not support grouping for checkboxes and radio buttons. There is an issue that adds that functionality. The grouped checkboxes and radio buttons are not visible in Gin theme.
How it is:

How it should be:

Steps to reproduce

  1. Install Drupal with the patch from https://www.drupal.org/node/2269823 β†’ and Gin as admin theme
  2. Create a list field with grouped options
  3. Change the field form display to Check boxes/radio buttons
  4. Visit the form with the grouped checkboxes

Proposed resolution

Don't put the single checkbox toggle styling on these checkboxes.

Remaining tasks

Create merge request

User interface changes

None

API changes

None

Data model changes

None

πŸ“Œ Task
Status

Closed: duplicate

Version

3.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium alduya

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.

  • πŸ‡§πŸ‡ͺBelgium beerendlauwers

    Issue is still present. @AkshayAdhav you probably did not test with a patch for 2269823, e.g. https://www.drupal.org/files/issues/2023-08-29/core-checkbox-groups-10.1... β†’ .

    To properly test it, you'll have to create your own FieldWidget that extends OptionsButtonsWidget, for example:

    namespace Drupal\my_example_module\Plugin\Field\FieldWidget;
    
    use Drupal\Core\Entity\FieldableEntityInterface;
    use Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsButtonsWidget;
    
    /**
     * Plugin implementation of the 'options_buttons' widget.
     *
     * @FieldWidget(
     *   id = "example_options_buttons",
     *   label = @Translation("Check boxes/radio buttons - With Groups"),
     *   field_types = {
     *     "boolean",
     *     "entity_reference",
     *     "list_integer",
     *     "list_float",
     *     "list_string",
     *   },
     *   multiple_values = TRUE
     * )
     */
    class ExampleOptionsButtonsWidget extends OptionsButtonsWidget
    {
        protected function getOptions(FieldableEntityInterface $entity)
        {
            return [
                'Top level label 1' => [
                    1 => 'Option one',
                    2 => 'Option two',
                ],
                'Top level label 2' => [
                    3 => 'Option three',
                    4 => 'Option four',
                ],
            ];
        }
    }
    

    Select the "Check boxes/radio buttons - With Groups" widget in the form display configuration. Trying it without a patch for 2269823 results in an error. With a patch, you'll see the behaviour displayed in the original issue description.

  • Status changed to Closed: cannot reproduce 4 months ago
  • πŸ‡¨πŸ‡­Switzerland saschaeggi Zurich

    Closing this again as it required a core patch to be applied. Once merged we can reopen it.

  • Status changed to Active about 2 months ago
  • πŸ‡«πŸ‡·France marabak

    The same issue is happening when enabling grouped checkboxes β†’ module.
    The input tag is hidden by css.

  • Status changed to Closed: duplicate about 2 months ago
  • πŸ‡¨πŸ‡­Switzerland saschaeggi Zurich

    Closing as duplicate of πŸ› Clientside validation breaks checkbox toggle Active

    Can you check if the solution there will fix your issue as well?

Production build 0.69.0 2024