Vinit Singh Vinit Singh - 11 months ago 55
PHP Question

Typed text not getting removed from kartik select2 after seleting option

Hi i am using kartik select2 in my yii application. The select box for selecting multiple options is working fine. However i am facing one small issue.
enter image description here

Like if i type ba then it will display all matching options. but when i press enter then Bakam get selected but the text ba remains in select box. It should get removed.
enter image description here

Here is code for my select box

<?= $form->field($model, 'area')->widget(Select2::classname(), [
'data' => [],
'options' => ['placeholder' => 'Select Location'],
'pluginOptions' => [
'closeOnSelect' => false,
'tags' => false,
'multiple' => true,
])->label("Reassign Location")

I checked it on kartik website the code seems fine then why the text remains there?

Answer Source

Set 'closeOnSelect' => true, in pluginOptions to remove selected option.