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&amp;idParent=4" data-method="post"><div class="btn btn-danger">Удалить</div></a> <?php ActiveForm::end(); ?> </li> <?php } 
  • By the way, with CheckboxX the same garbage. These widgets do not work on a bunch of models on one page - Krisha September
  • What do you have in $similar_pages and why for each of its elements to draw your own select2 ? - Al Mr

0