====== Kartik Select2 ======
===== Szkielet =====
use kartik\select2\Select2
=
$form->field($model, 'nazwa_pola')->widget(Select2::classname(), [
'data' => $data,
'options' => ['placeholder' => 'Wybierz...'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
===== Select 2 w modalu =====
Aby w modalu otworzyć Select2 auto-uzupełnianie należy w głównym kontenerze modala dodać tabindex="false"
Albo w jQuery:
$('.dod_wyk').click(function(e) {
e.preventDefault();
$('#myModal').attr('tabindex','false');
$('.modal-title').html('Dodaj użytkownika') ;
$('#myModal').modal('show').find('.modal-body')
.load($(this).attr('href'));
});
===== Select 2 w gidview jako filter =====
[
'attribute' => 'id_wykladowcy',
'format' => 'html',
'filterType' => GridView::FILTER_SELECT2,
'width' => '15%',
'filterWidgetOptions' => [
'data' => $wykladowcy,
'options' => ['prompt' => ''],
'size' => Select2::SMALL,
'pluginOptions' => [
'allowClear' => true,
],
],
'label' => 'Wykładowca',
'value' => function ($model) {
return $model->nazwisko;
}
]