I use http://demos.krajee.com/widget-details/select2#usage-tags controller
public function actionTagsForm()
{
$method = Yii::$app->request->isAjax ? 'renderAjax' : 'render';
$model = new UserTagsForm();
return $this->$method('tagsForm', ['model' => $model]);
}
views/layouts/main.php has code modal window
<?php
yii\bootstrap\Modal::begin([
'header' => '<div id="modalHeader"></div>',
'id' => 'modal',
'size' => 'modal-lg',
'options' => [
'tabindex' => false
],
]);
echo "<div id='modalContent'></div>";
yii\bootstrap\Modal::end();
?>
view
$data = [
"red" => "red",
"green" => "green",
"blue" => "blue",
"orange" => "orange",
"white" => "white",
"black" => "black",
"purple" => "purple",
"cyan" => "cyan",
"teal" => "teal"
]; ?>
<div class="image-tags-index">
<?php $form = ActiveForm::begin();?>
<?php echo $form->field($model, 'image_tags')->widget( Select2::classname(),[
'data' => $data,
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true
],
])->label('Tag Multiple');
?>
</div>
error
VM314:2 Uncaught ReferenceError: select2_3f25e3ac is not defined at eval (eval at globalEval (jquery.js:343), :2:56) at eval () at Function.globalEval (jquery.js:343) at domManip (jquery.js:5291) at jQuery.fn.init.append (jquery.js:5431) at jQuery.fn.init. (jquery.js:5525) at access (jquery.js:3614) at jQuery.fn.init.html (jquery.js:5492) at Object. (jquery.js:9436) at fire (jquery.js:3187)