Zend Framework

Allow for id attribute on optgroup elements

Details

  • Type: Patch Patch
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.5
  • Fix Version/s: 1.11.8
  • Component/s: Zend_Form
  • Labels:
    None

Description

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:

<select name="optgroup_test" id="optgroup_test">
    <optgroup id="option_group_1" label="Option Group 1">
        <option value="A" label="Option A">Option A</option>
        <option value="B" label="Option B">Option B</option>
        <option value="C" label="Option C">Option C</option>
    </optgroup>
    <optgroup id="option_group_2" label="Option Group 2">
        <option value="D" label="Option D">Option D</option>
    </optgroup>
</select>

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

$optgroupTest = new Zend_Form_Element_Select('optgroup_test');
$options = array (
    array(
        'id'    => 'option_group_1',
        'label' => 'Option Group 1',
        'options' => array (
            'A'     => 'Option A',
            'B'     => 'Option B',
            'C'     => 'Option C',
        ),
    ),
    array(
        'id'    => 'option_group_2',
        'label' => 'Option Group 2',
        'options' => array (
            'D'     => 'Option D',
        ),
    ),
);
$optgroupTest
    ->setLabel('Optgroup Test')
    ->addMultiOptions(
        $options
    )
;
  1. FormSelect.patch
    08/Nov/09 11:00 AM
    1 kB
    Bradley Holt
  2. ZF-8252.patch
    25/May/11 5:33 PM
    2 kB
    Kim Blomqvist

Activity

Hide
Bradley Holt added a comment -

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.

Show
Bradley Holt added a comment - 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.
Hide
Lukas Piliszczuk added a comment -

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

Show
Lukas Piliszczuk added a comment - Can't understand why this path is still not officially integrated to zf ? This is very usefull in the case of javascript multi select.
Hide
Matthew Weier O'Phinney added a comment -

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

Show
Matthew Weier O'Phinney added a comment - I think we need to address the array validation problem before applying this. Bradley, have you had a chance to look into that further?
Hide
Bradley Holt added a comment -

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

Show
Bradley Holt added a comment - Matthew, unfortunately I have not had a chance to look into the problem with the patch breaking the Array Validator.
Hide
Kim Blomqvist added a comment -

Patch attached

Show
Kim Blomqvist added a comment - Patch attached
Hide
Enrico Zimuel added a comment -

Solved in trunk (commit 24157)

Show
Enrico Zimuel added a comment - Solved in trunk (commit 24157)
Hide
Enrico Zimuel added a comment -

Solved in branches/release-1.11 (commit 24158)

Show
Enrico Zimuel added a comment - Solved in branches/release-1.11 (commit 24158)

People

Vote (5)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: