I'm a new Yii2.I've this bug, I don't know how can I solve this problem.
Bug is very simple templateSelection called two time. this is my code.
if I submit somethings in select2, templateSelection called two time.
echo Select2::widget([
'name' => 'blogId',
'options' => ['placeholder' => 'Search for [![enter image description here][1]][1] ...'],
'pluginOptions' => [
'allowClear' => true,
'minimumInputLength' => 1,
'ajax' => [
'url' => Url::to(['/controller/action']),
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {q:params.term}; }'),
'processResults' => new JsExpression($resultsJs),
],
'templateResult' => new JsExpression($formatRepo),
'templateSelection' => new JsExpression('function(params) { console.log("tst");}'),
],
]);
Thank you for your help.
I've found reponse myself by debuging select2.full.js
problem is right here. just remove this code. it call two time because it's nested function.
this.$element.on('change.select2', function () { self.dataAdapter.current(function (data) {
//self.trigger('selection:update', {
data: data });
// });
});