I
I
Iossarian2019-06-04 09:54:37
Yii
Iossarian, 2019-06-04 09:54:37

Why is the selected value not showing in Select2?

Hello. I have the following code using kartik\select2:

$user_profiles = ArrayHelper::merge(['' => 'Выберите пользователя'],
    ArrayHelper::map(Profile::find()->orderBy('full_name')->asArray()->all(), 'user_id',
        'full_name'))

\kartik\widgets\Select2::widget([
                        'name' => 'state_10',
                        'data' => $user_profiles,
                        'size' => \kartik\select2\Select2::SIZE_LARGE,
                        'pluginEvents' => [
                            "change" => 'function() { 
                    var data_id = $(this).val();
                    document.getElementById(\'userId\').value = data_id
                 }',
                        ],
                        'pluginOptions' => [
                            'tags' => true
                        ]
                    ]

The problem is that after selecting a value from the list, the widget's placeholder resets to 'Select a user' instead of displaying the selected list item. I get the correct value, the problem is only with its display. What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question