Select 2 in Active Form does not work for multiple models on the same page. The usual dropdown works correctly, but select does not generate select, but not span elements, that is, select becomes a hidden widget, but the span does not, therefore nothing is visible.
$similar_pages = SimilarPage::find() ->where(['id_page'=>$this->id]) ->select(['id','id_similar_page']) ->orderBy([ 'index' => SORT_ASC ]) ->all(); foreach ( $similar_pages as $sim_page) { ?> <li> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($sim_page, 'id_similar_page')->widget(Select2::classname(), [ 'data' => $pages, 'options' => ['placeholder' => 'Выберите страницу ...'], 'pluginOptions' => [ 'allowClear' => true ], ]); ?> <div class="form-group"> <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success' ] ) ?> </div> <a href="/similar-page/delete?id=3&idParent=4" data-method="post"><div class="btn btn-danger">Удалить</div></a> <?php ActiveForm::end(); ?> </li> <?php }
$similar_pagesand why for each of its elements to draw your ownselect2? - Al Mr