2017-09-11 92 views
0

即時通訊使用select2多選擇,在這個即時通訊獲取搜索所有項目,即使我有selectAll和Unseclect全部選項。但我想要的是在所有項目前面都有複選框。它就像標籤,以便他可以一次檢查項目並完成。 這是我當前的代碼。複選框中的每個項目select2多選

$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); 

回答

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');