ZF-8252: Allow for id attribute on optgroup elements

Issue Type: Patch Created: 2009-11-08T10:59:42.000+0000 Last Updated: 2011-06-27T15:32:52.000+0000 Status: Resolved Fix version(s): - 1.11.8 (07/Jul/11)

Reporter: Bradley Holt (bradley.holt) Assignee: Enrico Zimuel (zimuel) Tags: - Zend_Form

Related issues: Attachments: - FormSelect.patch


Zend_View_Helper_FormSelect does not allow optgroup elements to have an id attribute. Here is a patch that should allow for the following use case but should still be backwards compatible. This is not necessarily the best way to do this and could probably be a lot better: I put it together very quickly. The existing code doesn't seem to follow the Zend Framework coding standards so I kept my new code similar to the code that's already there. Again, this could be a lot more extensible than it is (e.g. it only allows for id and not class or other arbitrary decorators).

Here is the desired output:

<pre class="highlight">
Option AOption BOption COption D

Here is the use case that will give the desired output (with the patch applied):

<pre class="highlight">
$optgroupTest = new Zend_Form_Element_Select('optgroup_test');
$options = array (
        'id'    => 'option_group_1',
        'label' => 'Option Group 1',
        'options' => array (
            'A'     => 'Option A',
            'B'     => 'Option B',
            'C'     => 'Option C',
        'id'    => 'option_group_2',
        'label' => 'Option Group 2',
        'options' => array (
            'D'     => 'Option D',
    ->setLabel('Optgroup Test')


Posted by Bradley Holt (bradley.holt) on 2009-11-08T14:52:42.000+0000

I just found one problem with this patch. It breaks the In Array Validator on the Zend_Form_Element_Select. I've temporarily worked around this by calling setRegisterInArrayValidator(false) and manually adding my own In Array Validator with a haystack array that is in the format it likes. However, this is obviously not a good solution. There should be a way to get this new array format (or whatever array format is decided on) to work automatically with the In Array Validator.

Posted by Lukas Piliszczuk (lukaspili) on 2011-02-22T17:48:18.000+0000

Can't understand why this path is still not officially integrated to zf ? This is very usefull in the case of javascript multi select.

Posted by Matthew Weier O'Phinney (matthew) on 2011-03-01T10:54:05.000+0000

I think we need to address the array validation problem before applying this. Bradley, have you had a chance to look into that further?

Posted by Bradley Holt (bradley.holt) on 2011-03-02T07:28:50.000+0000

Matthew, unfortunately I have not had a chance to look into the problem with the patch breaking the Array Validator.

Posted by Kim Blomqvist (kblomqvist) on 2011-05-25T17:33:59.000+0000

Patch attached

Posted by Enrico Zimuel (zimuel) on 2011-06-27T15:15:38.000+0000

Solved in trunk (commit 24157)

Posted by Enrico Zimuel (zimuel) on 2011-06-27T15:32:52.000+0000

Solved in branches/release-1.11 (commit 24158)

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.