J
J
Justique2017-09-13 23:38:20
css
Justique, 2017-09-13 23:38:20

Why does Widget Select2 duplicate select?

kartik\select2 widget for yii2

$form->field($m, 'TourSearchFilter[country_from_id]')->widget(Select2::classname(), [
    'options' => ['placeholder' => 'Из любой страны','class' => 'select user-form firm-form', 'id'=>'cat-id-id'],
  'pluginOptions' => [
    'allowClear' => true,
    'minimumInputLength' => 2,
    'language' => 'ru',
    '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(country) { return country.text; }'),
    'templateSelection' => new JsExpression('function (country) { return country.text; }'),
  ],
])->label(false);

When I call, I get two selects.
f5e208d676394f8f860ea5357e303aa3.png
Can anyone come across this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Budaev, 2017-09-14
@Markus_Kane

I will assume that in addition to rendering the select2 widget by the form generator, you also call select2 in js.
That is, the Select2 package at the output gives you a ready-made widget (and it consists of a regular hidden select and a set of spans), and in js you attach the select2 function to the same hidden select.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question