Необходимо вывести
demos.krajee.com/widget-details/select2#usage-tags в модальном окне.
в main.php подключаю модальное окно
<?php
yii\bootstrap\Modal::begin([
'header' => '<div id="modalHeader"></div>',
'id' => 'modal',
'size' => 'modal-lg',
//keeps from closing modal with esc key or by clicking out of the modal.
// user must click cancel or X to close
'clientOptions' => ['backdrop' => 'static']
]);
echo "<div id='modalContent'></div>";
yii\bootstrap\Modal::end();
?>
контроллер
public function actionTagsForm()
{
$method = Yii::$app->request->isAjax ? 'renderAjax' : 'render';
$model = new UserTagsForm();
return $this->$method('tagsForm', ['model' => $model]);
}
вьюха отображения
<?php
$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>
если просто рендерить страницу то все отоброжается, если через аджакс то выдает ошибку
Uncaught ReferenceError: select2_3f25e3ac is not defined
at eval (eval at globalEval (jquery.js:343), <anonymous>:2:56)
at eval (<anonymous>)
at Function.globalEval (jquery.js:343)
at domManip (jquery.js:5291)
at jQuery.fn.init.append (jquery.js:5431)
at jQuery.fn.init.<anonymous> (jquery.js:5525)
at access (jquery.js:3614)
at jQuery.fn.init.html (jquery.js:5492)
at Object.<anonymous> (jquery.js:9436)
at fire (jquery.js:3187)