0

我使用 select2 多项选择,在此我正在搜索所有项目,即使我有 selectAll 和 Unseclect All 选项。但我想要的是在所有项目前面都有复选框。它就像标签,这样他就可以立即检查项目并完成..这是我当前的代码。

$form->field($tags, 'tag_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map(Tags::find()->where([])->all(), 'id', 
'tag_name'),
'language' => 'en',
'options' => ['placeholder' => 'Select Tags'],
'pluginOptions' => [
'allowClear' => true,
'multiple' => true,
],
])->label(false);
4

1 回答 1

2
$data = [
    "red" => "red",
    "green" => "green",
    "blue" => "blue",
    "orange" => "orange",
    "white" => "white",
    "black" => "black",
    "purple" => "purple",
    "cyan" => "cyan",
    "teal" => "teal"
];

// Tagging support Multiple
$model->colorTags =  ['red', 'green']; // initial value
echo $form->field($model, 'colorTags')->widget(Select2::classname(), [
    'data' => $data,
    'options' => ['placeholder' => 'Select a color ...', 'multiple' => true],
    'pluginOptions' => [
        'tags' => true,
        'tokenSeparators' => [',', ' '],
        'maximumInputLength' => 10
    ],
])->label('Tag Multiple');
于 2017-09-13T06:44:00.807 回答