Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.2.13

Bug #15955 On heirselect when you have more than two selects sub selects are not cleared
Submitted: 2009-02-27 01:16 UTC Modified: 2009-04-04 21:40 UTC
From: nickknight Assigned: avb
Status: Closed Package: HTML_QuickForm
PHP Version: 5.2.4 OS: Ubuntu Linux yaaa 2.6.24-21-386
Roadmaps: (Not assigned)    
Subscription  


 [2009-02-27 01:16 UTC] nickknight (Nick Knight)
Description: ------------ The sub selection of the heirselect do clear down the lower values when values up the chain are selected. Test script: --------------- require_once "HTML/QuickForm.php"; $form = new HTML_QuickForm('edit_template_form', 'post'); $sel =& $form->addElement('hierselect', 'subjecttypeid', 'Subject Type', null, ' - '); $mainOptions = array(1 => 'TV Shows', 2 => 'Movies', 5=>'Rubbish'); $secOptions = array(1 => array(5 => 'Stargate Atlantis', 4 => 'hello'), 2 => array(1 => 'Romance')); $thirdOptions = array(1 => array(5 => array(1 => 'Blah')), 2 => array(1 => array(21 => "ksjdhfks"))); $opts = array($mainOptions, $secOptions, $thirdOptions); //print_r($opts); $sel->setOptions($opts); $form->addElement('submit','Save','Save'); $form->display(); Expected result: ---------------- When using this example I expect to see 3 select boxes prodced - which are. When you select 'Rubbish' on the first select box I expect to see all subsequent boxes cleared. Actual result: -------------- The third box is not cleared. The value is whateer was in before from the previous tree selection. Many thanks Nick

Comments

 [2009-02-27 15:18 UTC] nickknight (Nick Knight)
in file heirselect.php: function _hs_findOptions(ary, keys) { // adding this bit fixes it if (ary==undefined) { return {}; } // end of fix var key = keys.shift(); if (!key in ary) { return {}; } else if (0 == keys.length) { return ary[key]; } else { return _hs_findOptions(ary[key], keys); } }
 [2009-04-03 22:13 UTC] avb (Alexey Borzov)
-Assigned To: +Assigned To: avb
I'll check the proposed fix, but please note that empty <select></select> tag that you desire is invalid in [X]HTML. Thus a better idea is to have options in second and third selects corresponding to value in the first one, even if these options read "N/A" or similar.
 [2009-04-04 21:40 UTC] avb (Alexey Borzov)
-Status: Assigned +Status: Closed
Applied the proposed fix. Thanks!