How do i create this with $this->formSelect() ?
<select multiple>
<optgroup label="a">
<option>1</option>
<option>2</option>
</optgroup>
<optgroup label="b">
<option>1</option>
</optgroup>
</select>
How do i create this with $this->formSelect() ?
<select multiple>
<optgroup label="a">
<option>1</option>
<option>2</option>
</optgroup>
<optgroup label="b">
<option>1</option>
</optgroup>
</select>
For the Zend_Form_Element_Select() it goes like this
$multiOptions = array(
'Group A' => array(1 => 'First Value',2 => 'Second Value A),
'Group B' => array(3 => 'Third Value'),
);
$element->setMultiOptions($multiOptions);
Note that you also have addMultiOption($option,$value) and addMultiOptions($options). Simply include the value or options in an additional array.
optgroup
is not a item you can select. In Zend the key for an array Group A
becomes a label and the label looks like a title in the drop down menu. See W3Schools –
Preter setMultiOptions()
no longer exists in Zend Framework 3. Use Mr Coder's answer instead. –
Infarct In Zend Framework 2 this can be done as follows:
$this->add(array(
'name'=>'Test',
'type'=>'Zend\Form\Element\Select',
'attributes'=>array('type'=>'select','required'=>'required'),
'options'=>array(
'label'=>'Test',
'value_options'=>array('fruits'=>array('label'=>'Fruits','options'=>array('1'=>'Apple','2'=>'Mango')),'animals'=>array('label'=>'Animals','options'=>array('cat'=>'CAT','dog'=>'DOG'))),
'empty_option'=>'Please Select'
),
));
please note that an option named empty_options doesn't exist instead empty_option should be used.
For the Zend_Form_Element_Select() it goes like this
$multiOptions = array(
'Group A' => array(1 => 'First Value',2 => 'Second Value A),
'Group B' => array(3 => 'Third Value'),
);
$element->setMultiOptions($multiOptions);
Note that you also have addMultiOption($option,$value) and addMultiOptions($options). Simply include the value or options in an additional array.
Group A
also a ID? like 001 –
Lixivium optgroup
is not a item you can select. In Zend the key for an array Group A
becomes a label and the label looks like a title in the drop down menu. See W3Schools –
Preter setMultiOptions()
no longer exists in Zend Framework 3. Use Mr Coder's answer instead. –
Infarct © 2022 - 2024 — McMap. All rights reserved.
Group A
also a ID? like 001 – Lixivium