← Back to team overview

mahara-contributors team mailing list archive

[Bug 1497341] [NEW] Pieforms "select" rule validation with optgroups fails

 

Public bug reported:

The validation for pieform select elements fails in some cases when
optgroups are used. Mahara 15.04.3 used but this will affect previous
versions going back to the introduction of optgroup support.

I think this may only affect optgroups that have an integer as the key.
Example optgroup array to reproduce the issue:


$optgroup = array(
    array("label" => "Test Group 1", "options" => array(
        1 => "Option 1",
        2 => "Option 2"
    )),
    array("label" => "Test Group 2", "options" => array(
        3 => "Option 3",
        4 => "Option 4"
    ))
);

$elements['example_optgroup_select'] = array(
    'type' => 'select',
    'description' => "Choose an option",
    'optgroups' => $optgroup,
    'title' => "Example optgroup select",
    'rules' => array()
);


Selecting "Option 4" will cause the validation to throw an error: The option "4" is invalid.

The issues appears to be in the "pieform_element_select_get_options"
function in htdocs/lib/pieforms/pieform/elements/select.php

Specifically:

foreach ($element['optgroups'] as $optgroup) {
   $options = array_merge($options, $optgroup['options']);
}

To retain the array key required for validation I believe this should
be:

foreach ($element['optgroups'] as $optgroup) {
   $options = $options + $optgroup['options'];
}

** Affects: mahara
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Mahara
Contributors, which is subscribed to Mahara.
Matching subscriptions: Subscription for all Mahara Contributors -- please ask on #mahara-dev or mahara.org forum before editing or unsubscribing it!
https://bugs.launchpad.net/bugs/1497341

Title:
  Pieforms "select" rule validation with optgroups fails

Status in Mahara:
  New

Bug description:
  The validation for pieform select elements fails in some cases when
  optgroups are used. Mahara 15.04.3 used but this will affect previous
  versions going back to the introduction of optgroup support.

  I think this may only affect optgroups that have an integer as the
  key. Example optgroup array to reproduce the issue:

  
  $optgroup = array(
      array("label" => "Test Group 1", "options" => array(
          1 => "Option 1",
          2 => "Option 2"
      )),
      array("label" => "Test Group 2", "options" => array(
          3 => "Option 3",
          4 => "Option 4"
      ))
  );

  $elements['example_optgroup_select'] = array(
      'type' => 'select',
      'description' => "Choose an option",
      'optgroups' => $optgroup,
      'title' => "Example optgroup select",
      'rules' => array()
  );

  
  Selecting "Option 4" will cause the validation to throw an error: The option "4" is invalid.

  The issues appears to be in the "pieform_element_select_get_options"
  function in htdocs/lib/pieforms/pieform/elements/select.php

  Specifically:

  foreach ($element['optgroups'] as $optgroup) {
     $options = array_merge($options, $optgroup['options']);
  }

  To retain the array key required for validation I believe this should
  be:

  foreach ($element['optgroups'] as $optgroup) {
     $options = $options + $optgroup['options'];
  }

To manage notifications about this bug go to:
https://bugs.launchpad.net/mahara/+bug/1497341/+subscriptions


Follow ups