2016-12-06 122 views
0

通過使用鋰形式助手,我們可以插入一個select標籤,可以選擇單個項目。鋰:正確使用select2與`multiple`選項

樣本:

echo $this->form->field('myfield', array(
    'type' => 'select', 
    'list' => array(
     'id1' => 'value1', 
     'id2' => 'value2', 
     ), 
    ) 
); 

現在,如果你想使用Select2 jQuery插件與multiple選項,在form helper嘗試field方法檢索字符串提交的值。 即使設置了multiple選項!

非工作樣品:

echo $this->form->field('myfield', array(
    'type' => 'select', 
    'list' => array(
     'id1' => 'value1', 
     'id2' => 'value2', 
     ), 
    'multiple' => true, 
    ) 
); 

回答

0

field方法將不接受在提交的表單數組值。

所以嘗試select方法在窗體幫助multiple選項。

示例代碼:

echo $this->form->select('myfield', 
    array(
     'id1' => 'value1', 
     'id2' => 'value2', 
    ), 
    array(
     'multiple' => true, 
    ) 
);