D
D
denop2019-09-30 23:38:44
Yii
denop, 2019-09-30 23:38:44

Search box not showing in Yii2 - Kartik Select2?

Welcome all!
In Yii2 I use the plugin Kartik Select2 (Ajax Loading) I encountered
the following issues:
1. When using Bootstrap Tabs, the input was not displayed . I
found a solution: added 'style'=>[' to the options array; display:inline !important']
2. The search field is not displayed
5d9266d74f379118010456.png
standard field code from the docks
tried to add 'hideSearch' => false, (default value)
still didn't change anything
Issue resolved.
The problem turned out to be that this field (model and field) is already used on this screen, it
is solved by adding 'id' => 'search-name' to the options array,
but this raises the following question:

The search takes place on the Name field. How best to network the incoming id?

- create a separate model for the search?
- or create a separate column in the database with a name like 'search_name'?

echo $form->field($usersClient, 'client_name')->widget(Select2::classname(), [
                    'options' => [
                            'placeholder' => 'Выбрать клиента ...',
                            'style'=>['; display:inline !important']
                    ],
                    //'hideSearch' => false,
                    'pluginOptions' => [
                        'allowClear' => true,
                        'minimumInputLength' => 1,
                        'language' => [
                            'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }")
                        ],
                        'ajax' => [
                            'url' => $url,
                            'dataType' => 'json',
                            'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                        ],
                        'escapeMarkup' => new JsExpression('function (markup) {console.log(markup); return markup; }'),
                        'templateResult' => new JsExpression('function(client) {console.log(client); return client.text; }'),
                        'templateSelection' => new JsExpression('function (client) {console.log(client); return client.text; }')
                    ]
                ]);

The controller is also from the docks - it works, it returns Json in the required format
5d9265cbf05bf077143704.png
Perhaps someone came across and solved it.
Thanks in advance for your replies!

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