即时通讯使用select2 multiple select,在这里我可以搜索所有项目,即使我有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);
答案 0 :(得分: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');