I'm trying to create a Zend_Form_Element_Select with option groups
(optgroup) that each have their own class or id (preferably id). Is
there a way to do this? I need to be able to select specific optgroups
in JavaScript to enable/disable them which is why I need an id or
class (selecting on label would be a messy hack). Here is code similar
to what I'm using:

---

        $optgroupTest = new Zend_Form_Element_Select('optgroup_test');
        $options = array (
            'Option Group 1'    => array (
                'A'     => 'Option A',
                'B'     => 'Option B',
                'C'     => 'Option C',
            ),
            'Option Group 2'    => array (
                'D'     => 'Option D',
            ),
        );
        $optgroupTest
            ->setLabel('Optgroup Test')
            ->addMultiOptions(
                $options
            )
        ;

---

The corresponding output:

---

<select name="optgroup_test" id="optgroup_test">
    <optgroup 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 label="Option Group 2">
        <option value="D" label="Option D">Option D</option>
    </optgroup>
</select>

---

The desired output (note the id on the two optgroup elements):

---

<select name="optgroup_test" id="optgroup_test">
    <optgroup label="Option Group 1" id="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 label="Option Group 2" id="option_group_2">
        <option value="D" label="Option D">Option D</option>
    </optgroup>
</select>

---

Is there any way with Zend_Form_Element_Select to get this desired
output? As I said before, either an id or class on optgroup elements
would be acceptable.

Thanks,
Bradley

Reply via email to