When the webform has a select options field with only 1 option and is set to multiple (to have a single on/off checkbox) and the key is 0 the download shows the checkbox always checked.

  • When multiple is not set, the download shows the results correct. But then we have a radio instead of checkbox.
  • When there is more than 1 option the download is also correct.
  • xls of csv export does not make any difference.
  • When the key is 1 instead of 0 the download is correct.

Tested on a fresh Drupal installation with webform 4.10 and dev.

Comments

hansrossel created an issue. See original summary.

hansrossel’s picture

Issue summary: View changes
hansrossel’s picture

Issue summary: View changes
StatusFileSize
new17.43 KB
hansrossel’s picture

Issue summary: View changes
hansrossel’s picture

Must be something wrong in this part of /webform/components/select.inc at line 819 in the case the key is 0 and there is only 1 item in multiple.

/**
 * Implements _webform_csv_data_component().
 */
function _webform_csv_data_select($component, $export_options, $value) {
  $options = _webform_select_options($component, TRUE);
  $return = array();

  if ($component['extra']['multiple']) {
    foreach ($options as $key => $item) {
      $index = array_search($key, (array) $value);
      if ($index !== FALSE) {
        if ($export_options['select_format'] == 'separate') {
          $return[] = 'X';
        }
        else {
          $return[] = $export_options['select_keys'] ? $key : $item;
        }
        unset($value[$index]);
      }
      elseif ($export_options['select_format'] == 'separate') {
        $return[] = '';
      }
    }
danchadwick’s picture

Title: Download of multiple select options with 1 option shows always checked » Download of multiple select options with key of 0 shows always checked
Version: 7.x-4.10 » 7.x-4.x-dev
Status: Active » Fixed
StatusFileSize
new1.02 KB

Right you are. Reproduced. The problem is with a key of '0', such as

0|No
1|Maybe
2|Yes

An completed but empty component has an empty string stored as its value. This indicates that that, when presented again, the default should not be made again. The problem is that the empty string is being confused by PHP with the 0 key.

Committed to 7.x-4.x and 8.x.

  • DanChadwick committed 65b5656 on 8.x-4.x
    Issue #2568637 by DanChadwick: Fixed download of multiple select options...

  • DanChadwick committed eaf1436 on
    Issue #2568637 by DanChadwick: Fixed download of multiple select options...
hansrossel’s picture

Thanks a lot, I tested it and it indeed solves the problem.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.