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

Default check values in tableselect aren't set properly for a 0-based array.

$
0
0

Problem/Motivation

In a tableselect entity, one can supply an array of default values, but with a normal array with index starting at 0, the first element will never get checked by default.

In core function form_process_tableselect in form.inc, I notice that effectively, the index of the row is copied in the row's default checkvalue, so if the index is 0, it will get a 0 value and uncheck the box instead of check it. Since I didn't find any documentation stating that the default_values array must not start with element 0, I assume that this is a bug in the construction of the tableselect layout.

Steps to reproduce

Example:

  for( $j=0; $j < $max; $j++ ) {
    $default_value[$j] = 1;
  }  


  $form['candidates2'] = array 
  (
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $table,
    '#multiple' => true,
    '#default_value' =>$default_value, 
    
  ); 

This leaves the first box unchecked, but if you supply the array

  for( $j=1; $j <= $max; $j++ ) {
    $default_value[$j] = 1;
  }  

Then all boxes are checked.

Proposed resolution

TBA

Remaining tasks

See #16

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 298117

Trending Articles



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