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
Posted by Matthieu Larcher (mattso) on 2011-04-18T18:15:00.000+0000
the updated FormSelect file
Posted by Matthieu Larcher (mattso) on 2011-04-18T18:18:11.000+0000
the patch
Posted by Matthieu Larcher (mattso) on 2011-04-18T18:45:28.000+0000
The test
Posted by Matthieu Larcher (mattso) on 2011-04-18T18:58:21.000+0000
the patch for the test
Posted by Matthieu Larcher (mattso) on 2011-04-18T21:35:02.000+0000
The files I posted allow for the described behaviour.
Posted by Matthew Weier O'Phinney (matthew) on 2011-04-18T21:46:11.000+0000
Re-opening as the patches have not been applied against the repository.
Posted by Kai Uwe (kaiuwe) on 2011-04-19T06:21:00.000+0000
@Matthieu
Please review the patch file "FormSelect.patch" because there is no need to replace all of the code.
Posted by Matthieu Larcher (mattso) on 2011-04-19T08:50:44.000+0000
Here's the fixed patch file. Looks like tortoissvn went crazy on the previous one, I created this one through smartsvn.
Posted by Kai Uwe (kaiuwe) on 2011-04-20T06:16:03.000+0000
Code tags added.
Posted by Matthieu Larcher (mattso) on 2012-10-15T21:31:48.000+0000
Is there any reason why this ticket is still opened when I provided the required patch and test when opening it ?
Posted by Matthew Weier O'Phinney (matthew) on 2012-10-16T15:13:58.000+0000
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.
Posted by Matthew Weier O'Phinney (matthew) on 2012-10-16T15:30:43.000+0000
Merged to trunk and 1.12 release branch.
Posted by Matthieu Larcher (mattso) on 2012-10-16T21:12:21.000+0000
Thank you for taking the time to handle this.