A
A
Anatoly Medvedev2016-07-28 17:18:01
JavaScript
Anatoly Medvedev, 2016-07-28 17:18:01

How to make Select2 expand on all keys except Enter?

I use this widget for Yii2 to use Select2.

echo \kartik\select2\Select2::widget([
                'name' => 'details',
                'value' => '',
                'readonly' => true,
                'pluginLoading' => false,
                'theme' => \kartik\select2\Select2::THEME_BOOTSTRAP,
                'data' => \yii\helpers\ArrayHelper::map(\app\models\DetailNames::find()->orderBy("Name")->all(), 'id', 'Name'),
                'options' => ['placeholder' => 'Деталь'],
                'pluginOptions' => [
                    'allowClear' => true
                ],
                'pluginEvents' => [
                    "select2:select" => "function(data) {  searchParts.idDetail = data.params.data.id; }",
                    "select2:unselect" => "function() { searchParts.idDetail = false; }",
                ],
            ]);


resulting html (who needs it)
<select id="w0" class="form-control select2-hidden-accessible" name="details" readonly="" data-s2-options="s2options_6cc131ae" data-krajee-select2="select2_c2410efe" tabindex="-1" aria-hidden="true">
<option value="">Деталь</option>
<option value="">Деталь1</option>
<option value="">Деталь2</option>
<option value="">Деталь3</option>
</select>
<span class="select2 select2-container select2-container--bootstrap select2-container--below select2-container--focus" dir="ltr" style="width: 100%;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-w0-container"><span class="select2-selection__rendered" id="select2-w0-container"><span class="select2-selection__placeholder">Деталь</span></span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>


Here's how to make it so that if the focus is on it, then the search starts by pressing any key and not just Enter, Spase, Alt + Down, but at the same time disable this behavior by Enter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2016-08-06
@IgorBee

What's the problem?
set the condition when you press the key to open like except chart code Inter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question