A
A
AlexSer2019-04-07 14:22:16
Yii
AlexSer, 2019-04-07 14:22:16

How to properly organize the output in the Select2 yii2 card?

Please tell me how to correctly display the results with spaces. Here is the code:

echo Select2::widget([
            'id'=>'pacients',
            'name' => 'kv_theme_select2',
            'initValueText' =>'', // set the initial display text
            'theme' =>  Select2::THEME_CLASSIC, // this is the default if theme is not set
            'options' => ['placeholder' => 'Поиск пациента'],
            'pluginOptions' => [
                'minimumInputLength' => 7,
                'allowClear' => true,
                '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(user) { return  user.surname +user.name +user.fathername +  user.birthday;}'),
                'templateSelection' => new JsExpression('function (pacients) { return pacients.surname+pacients.name+pacients.fathername+pacients.birthday;}'),
            ],
        ]);

        ?>

When entering initials, a search occurs. But the select displays data without spaces. I would like that when entering, the full data would be displayed, and when choosing, the surname and initials would already be displayed.
Here's what it looks like now
5ca9dd5b04383438617617.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-04-08
@AlexSer

You set the format yourself:
What prevents a space from being inserted
user.surname + ' ' + user.name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question