ZF-11302: Setting class on a select option

Description

Adding the possibility to pass a class to options in Zend_View_Helper_FormSelect

When dynamically creating a select in a form, it can be useful to set a specific class on each option tag you create. A typical use case would be to be able to restrict the options available through javascript according to this class.

The list of classes to use for each element would be passed through attribs in the form of an array associating the value of the option to the desired class. That would look something like this :


foreach ($locations as $location) {
    $form->location_id->addMultiOption($location->id, $location->name);

    $optionClasses = $form->location_id->getAttrib('optionClasses');
    $optionClasses = (!$optionClasses) ? array() : $optionClasses;
    $optionClasses[$location->id] = 'dept_' . $location->department->code . ' postCode_' . $location->postCode;

    $form->location_id->setAttrib('optionClasses', $optionClasses);
}

Comments

the updated FormSelect file

the patch

The test

the patch for the test

The files I posted allow for the described behaviour.

Re-opening as the patches have not been applied against the repository.

@Matthieu

Please review the patch file "FormSelect.patch" because there is no need to replace all of the code.

Here's the fixed patch file. Looks like tortoissvn went crazy on the previous one, I created this one through smartsvn.

Code tags added.

Is there any reason why this ticket is still opened when I provided the required patch and test when opening it ?

We don't resolve issues unless (a) a fix is in, (b) the patch provided in the issue has been applied and/or (c) we decide we can't use the patch or will not address the issue.

Please don't close this again.

Merged to trunk and 1.12 release branch.

Thank you for taking the time to handle this.