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

Created on 30 January 2012, almost 13 years ago
Updated 23 February 2023, over 1 year ago

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 🐛 Default check values in tableselect aren't set properly for a 0-based array. Needs work

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

9.5

Component
Form 

Last updated about 22 hours ago

Created by

🇧🇪Belgium LeoDoms

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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