A
A
Alexander Pantyukhov2016-08-30 11:55:28
JavaScript
Alexander Pantyukhov, 2016-08-30 11:55:28

How in select2 to make that after selection the window is not closed?

Good day. There is a select like this:

echo $form->field($modelForm, 'applicationId')->widget(\kartik\widgets\Select2::classname(), [
    'options' => [
        'placeholder' => 'All',
        'style' => "width:300px",
        'id' => 'applicationId',
        'multiple' => true,
    ],
    'initValueText' => $modelForm->selectedApplication,
    'pluginOptions' => [
        'width' => '460px',
        'allowClear' => true,
        'minimumInputLength' => 3,
        'ajax' => [
            'url' => $urlApplication,
            'dataType' => 'json',
            'delay' => 350,
            'data' => new \yii\web\JsExpression('function(term,page) {
                        var marketId=$("#marketId").select2("val");
                        var marketAccountId=$("#marketAccountId").select2("val");
                        var platformId=$("#platformId").select2("val");
                        if(typeof platformId !== "string" && platformId != null && platformId.length > 0){
                            platformId = platformId.join(",");
                        }
                        if(typeof marketAccountId !== "string" && marketAccountId != null && marketAccountId.length > 0){
                            marketAccountId = marketAccountId.join(",");
                        }
                        if(typeof marketId !== "string" && marketId != null && marketId.length > 0){
                            var market = marketId.join(":")
                        }
                        var search=term.term;
                        search=search.replace(/\'/g,"");
                        return {marketId:market,platformId:platformId,marketAccountId:marketAccountId,search:search};
                }'),
            'results' => new \yii\web\JsExpression('function(data,page) {return {results:data.results}; }'),
        ],
        'escapeMarkup' => new \yii\web\JsExpression('function (markup) { return markup; }'),
        'templateResult' => new \yii\web\JsExpression('format'),
        'templateSelection' => new \yii\web\JsExpression('function (city) { return city.text; }'),
    ],
]);

In JS, if you do:
$("#applicationId").on("select2:select",  function (e) { $("#applicationId").select2("open") });
then it closes after selection, then opens, i.e. if there was a search, then it is reset. How to make it so that after selecting select2 it would remain open and with the search that was filled before?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-08-30
@Paromon

the Select2 plugin has a closeOnSelect option that is responsible for the functionality you need.

'pluginOptions' => [
 'closeOnSelect' => false
]

More details can be found in the official documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question