[英]<optgroup> in admin form field
我有一個管理表單,其中包含在我的_prepareForm
方法中聲明的幾個 select 字段,如下例所示:
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'datacenter_action_form',
'action' => $this->getUrl('*/*/saveConfig'),
'method' => 'post',
'enctype' => 'multipart/form-data'
));
$fieldset = $form->addFieldset('base_fieldset', array('legend' => 'Example');
$fieldset->addField('entity', 'select', array(
'name' => 'action[entity]',
'title' => 'Entity',
'label' => 'Entity',
'required' => true,
'values' => array('one','two')
));
...
return parent::_prepareForm();
}
我想知道是否可以通過嵌套值將optgroups
添加到字段值,就像在source models
中可能的方式一樣:
...
$fieldset->addField('entity', 'select', array(
'name' => 'action[entity]',
'title' => 'Entity',
'label' => 'Entity',
'required' => true,
'values' => array('value' => array('one','two'), 'label' => 'Numbers')
));
...
預期的 output 將是:
<select> <optgroup label="Numbers"> <option>one</option> <option>two</option> </optgroup> </select>
Obs.: 我已經嘗試過 model 與源 model 中相同的方式(通過嵌套值),但它似乎不起作用
可以通過嵌套以下選項來實現:
...
$fieldset->addField('entity', 'select', array(
'name' => 'action[entity]',
'title' => 'Entity',
'label' => 'Entity',
'required' => true,
'values' => array(
array('value' => array(
array('value' => 'one', 'label' => 'One'),
array('value' => 'two', 'label' => 'Two')
), 'label' => 'Numbers'))
));
...
我嵌套錯了:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.