Select2 and Ajax laoding, search but I can't choose result

Hi.

I’m using: Select2 and Ajax laoding from tutorial: http://demos.krajee.com/widget-details/select2#usage-ajax

I have problem script work but I can’t choose value

Form:


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

        'initValueText' => 'TEST', // set the initial display text

        'options' => ['placeholder' => 'Szukaj'],

        'pluginOptions' => [

            'allowClear' => true,

            'minimumInputLength' => 3,

            'ajax' => [

                'url' => $url,

                'dataType' => 'json',

                'data' => new JsExpression('function(params) { return {q:params.term}; }')

            ],

            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),

            'templateResult' => new JsExpression('function(surname) { return surname.text; }'),

            'templateSelection' => new JsExpression('function (surname) { return surname.text; }'),

        ],

    ]);?>

Controller:


public function actionSurnamelist($q = null, $id = null) {

        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

        $out = ['results' => ['id' => '', 'text' => '']];

        if (!is_null($q)) {

            $query = new Query;

            $query->select('surname_id, surname_name AS text')

                ->from('surname')

                ->where(['like', 'surname_name', $q])

                ->limit(20);

            $command = $query->createCommand();

            $data = $command->queryAll();

            $out['results'] = array_values($data);

        }

        elseif ($id > 0) {

            $out['results'] = ['id' => $id, 'text' => Surname::find($id)->surname_name];

        }

        return $out;

    }

How to view this problem, I can’t click on result:

Here was image but I can’t upload on server

I throw a proper solution can someone come in handy :

Controller:


public function actionSurnamelist($q = null, $id = null)

    {

        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

        $out = ['results' => ['top_surname_surname_id' => '', 'text' => '']];

        if (!is_null($q)) {

            $query = new Query;

            $query->select('surname_id AS id, surname_name AS text')

                ->from('surname')

                ->where(['like', 'surname_name', $q])

                ->limit(20);

            $command = $query->createCommand();

            $data = $command->queryAll();

            $out['results'] = array_values($data);

        } elseif ($id > 0) {

            $out['results'] = ['top_surname_surname_id' => $id, 'text' => Surname::find($id)->surname_name];

        }

        return $out;

    }

View:


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

//        'initValueText' => '', // set the initial display text

        'options' => ['placeholder' => 'Wpisz nazwisko'],

        'pluginOptions' => [

            'allowClear' => true,

            'minimumInputLength' => 3,

            'ajax' => [

                'url' => $url,

                'dataType' => 'json',

                'data' => new JsExpression('function(params) { return {q:params.term}; }')

            ],

            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),

            'templateResult' => new JsExpression('function(surname) { return surname.text; }'),

            'templateSelection' => new JsExpression('function (surname) { return surname.text; }'),

        ],

    ]); ?>