Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291302

Disabling tableselect element options

$
0
0

Problem/Motivation

There's no handy way to mark some rows as disabled for selection in a tableselect element.

Proposed resolution

Allow to pass an optional #disabled property in option. When an option has #disabled === TRUE, the corresponding checkbox will be disabled.

Workaround

Without this change there's still possible to disable certain rows:

  1. Add an additional #process callback to the tableselect element. Note that you should add also the original processor:
    $form['my_table'] = [
      '#type' => 'tableselect',
      ...
      '#process' => [
        // This is the original #process callback.
        [Tableselect::class, 'processTableselect'],
        // Additional #process callback.
        [static::class, 'processDisabledRows'],
      ],
      ...
    ];
    
  2. The additional #process callback:
    public static function processDisabledRows(array &$element): array {
      foreach (Element::children($element) as $key) {
        $element[$key]['#disabled'] = isset($element['#options'][$key]['#disabled']) ? $element['#options'][$key]['#disabled'] : FALSE;
      }
      return $element;
    }
    
  3. Set the #disabled property to TRUE on the rows that you want to disable:
    $form['my_table'] = [
      '#type' => 'tableselect',
      ...
      '#options' => [
        'row1' => [
          'col1' => '1.1',
          'col2' => '1.2',
        ],
        // This row is disabled.
        'row2' => [
          'col1' => '2.1',
          'col2' => '2.2',
          '#disabled' => TRUE,
        ],
      ],
      ...
    ];
    

Remaining tasks

None.

User interface changes

API changes

A tableselect element can have disabled options.

Data model changes

None.

Release notes snippet

By adding a #disabled property set to TRUE, it's possible to prevent used by selecting certain options in a tableselect form element.

Initial report

Currently it is not possible to disable an option on a tableselect list.
Can we allow a Tableselect checkbox to be disabled on a specific option, like it currently is possible with the attribute and ajax parameters?


Viewing all articles
Browse latest Browse all 291302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>