PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_QuickForm » Bug #6766

hierselect problem with HTML_QuickForm_Controller

Details

Submitted2006-02-13 10:45 UTC
Fromigor dot grzalja at gmail dot com
Assignedavb
StatusClosed
PackageHTML_QuickForm
PHP Version4.4.2
OSWindows XP, Linux
Roadmaps(Not assigned)

Comments

[2006-02-13 10:45 UTC] igor dot grzalja at gmail dot com

Description:
------------
Bug occurs if you need multiple select for a second field, and you have specified required rule on hierselect.

Test script:
---------------
class Page_Account_Credentials extends HTML_QuickForm_Page
{

function buildForm()
{
$this->_formBuilt = true;

$buttons[0] =& HTML_QuickForm::createElement('button', 'cancel', 'Cancel', array('onclick'=>"javascript:location.href='http://pear.php.net/package/HTML_QuickForm';"));
$buttons[1] =& HTML_QuickForm::createElement('submit', $this->getButtonName('next'), 'Next step >>');
$this->addGroup($buttons, 'buttons', '', '&nbsp', false);

$services[0] = "Pop";
$services[1] = "Rock";
$services[2] = "Classical";

$subservices[0][0] = "Belle & Sebastian";
$subservices[0][1] = "Elliot Smith";
$subservices[0][2] = "Beck";
$subservices[1][3] = "Noir Desir";
$subservices[1][4] = "Violent Femmes";
$subservices[2][5] = "Wagner";
$subservices[2][6] = "Mozart";
$subservices[2][7] = "Beethoven";

$hireselect =& $this->addElement('hierselect', 'ihierselServices', 'Servisi:', array('style' => 'width: 20em;'), '<br /><br />Usluge:<br />');
$hireselect->setOptions(array($services, $subservices));
$hsElements =& $hireselect->getElements();
$hsElements[0]->setSize(10);
$hsElements[0]->setMultiple(false);
$hsElements[1]->setSize(10);
$hsElements[1]->setMultiple(true);

$this->addGroupRule('ihierselServices', 'Choose at least one.', 'required');

$this->setDefaultAction('next');
}
}

Expected result:
----------------
When you submit the form without choosing any item form second list you get notice that you require to choose some items. Fine. Until now everything works fine.
BUT... an error (js object expected) occurs when you try to change selected item form a first select.

I think the problem is in HTML_QuickForm_hierselect::setValue($value) since this function does
$this->_nbElements = count($value);

which is 1 if you did not choose any item form second select.

If you change this line to:
$this->_nbElements = count($this->_elements);

I think this is the bugfix.