Kartik Select2 Dropdown issues [Solved]




use kartik\select2\Select2;


<?= $form->field($profile, 'associationSelect')->widget(Select2::classname(), [

    'data' => $associationList,

    'language' => 'en',

    'theme' => 'krajee',

    'options' => ['placeholder' => 'Select Association ...'],

    'pluginOptions' => ['allowClear' => true],

])->label(''); ?>



This widget works fine when there is no initial value. However, when there is an initial value, the widget only shows the placeholder. I can work around this by using [‘placeholder’ => $placeholder] and setting $placeholder to NULL whenever an initial value exists. However, if the placeholder is NULL and an initial value is showing, then allowClear doesn’t work. The “x” shows up, but doesn’t do anything when clicked. I have several dropdowns in my app and they all have these issues.

$associationList is an array like {[1]=>"association1", [2]=>"association2", [3] …}

What am I doing wrong?

The problem was that ‘associationSelect’ is an internal attribute. I switched to a db attribute and it works fine now.