Views InOperator "Select all" option should only be applied when the valueFormType is "checkboxes"

Created on 3 November 2017, almost 7 years ago
Updated 7 February 2023, over 1 year ago

Problem/Motivation

Currently the InOperator views filter class is heavily subclassed and allows developers to customise the "value form type" with a protected property. As a nice bit of utility, in the admin form the InOperator allows users to select all values with a "Select all" option.

Currently 'ManyToOne' overrides this, which is used by the user role filter, see current broken behavior in HEAD:

This option only makes sense for checkboxes because:

  • Other types of elements like radios can only have one option selected.
  • Other types of elements like multi select-lists already heavy easy native bulk selection.

Relevant code:

    $exposed = $form_state->get('exposed');
    if (!$exposed) {
      // Add a select all option to the value form.
      $options = ['all' => $this->t('Select all')];
    }
  Drupal.behaviors.viewsFilterConfigSelectAll = {
    attach: function attach(context) {
      var $context = $(context);

      var $selectAll = $context.find('.js-form-item-options-value-all').once('filterConfigSelectAll');
      var $selectAllCheckbox = $selectAll.find('input[type=checkbox]');
      var $checkboxes = $selectAll.closest('.form-checkboxes').find('.js-form-type-checkbox:not(.js-form-item-options-value-all) input[type="checkbox"]');

      if ($selectAll.length) {
        $selectAll.show();
        $selectAllCheckbox.on('click', function () {
          $checkboxes.prop('checked', $(this).is(':checked'));
        });

        $checkboxes.on('click', function () {
          if ($(this).is('checked') === false) {
            $selectAllCheckbox.prop('checked', false);
          }
        });
      }
    }
  };

Proposed resolution

Only add the "Select all" option if the $valueFormType is "checkboxes".

Remaining tasks

Agree and patch.

User interface changes

Fixes a dud option for sub-classes of InOperator.

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

10.1

Component
Views 

Last updated about 6 hours ago

Created by

🇦🇺Australia Sam152

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