Yii Framework Forum: Kartik Select2 Dropdown issues [Solved] - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Kartik Select2 Dropdown issues [Solved] placeholder and initial value not working correctly Rate Topic: -----

#1 User is offline   SteveM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 67
  • Joined: 26-October 15
  • Location:Navan, Ireland

Posted 09 August 2016 - 07:33 PM

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?
0

#2 User is offline   SteveM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 67
  • Joined: 26-October 15
  • Location:Navan, Ireland

Posted 18 August 2016 - 05:56 PM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users