【问题标题】:Lithium: Correct use of select2 with `multiple` option锂:正确使用带有 `multiple` 选项的 select2
【发布时间】:2016-12-06 07:51:16
【问题描述】:

通过使用 Lithium 表单助手,我们可以插入一个可以选择单个项目的 select 标签。

样本:

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

现在如果你想使用带有multiple 选项的Select2 jQuery 插件,form helper 中的field 方法会尝试检索字符串中提交的值。 即使设置了multiple 选项!

非工作样本:

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

【问题讨论】:

    标签: jquery-select2 lithium


    【解决方案1】:

    field 方法不接受提交表单中的数组值。

    所以尝试在表单助手中使用select 方法和multiple 选项。

    示例代码:

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

    【讨论】:

      猜你喜欢
      • 2016-02-24
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多