Open mavelar opened 5 years ago
I have the same issue, however it is Cannot read property 'id' of undefined
instead.
I am using it as a filter with the gridview:
[
'attribute' => 'repairer.name',
'label' => 'Repairer',
'filterType' => GridView::FILTER_SELECT2,
'filterWidgetOptions' => [
'pluginOptions' => [
'allowClear' => true,
'ajax' => [
'url' => Url::to(['/contact/list', 'mode' => 'repairer']),
'dataType' => 'json',
'delay'=> 10,
'data' => new JsExpression('function(params) { return { q: params.term, page: params.page}; }'),
'cache' => true
]
]
]
],
My solution was to add a placeholder. This seems to have fixed it:
'options' => ['placeholder' => ''],
My current code is like this:
<?=$form->field($model,'customer_id')->widget(Select2::classname(), [ 'data' => ArrayHelper::map($customer,'id','customer_name'), 'theme' => 'bootstrap', 'options' => [ 'placeholder' => Yii::t('app','Select customer...'), ], 'pluginOptions' => [ 'allowClear' => true ], ])->label(Yii::t('app','Customer'));?>
As you can see allowClear is set true, but when I try to clear my selection a javascript error is trigger:
TypeError: $el.data(...) is undefined
And refer to line 91
initS2Unselect = function () { var $el = $(this), opts = $el.data('select2').options; opts.set('disabled', true); setTimeout(function() { opts.set('disabled', false); $el.trigger('krajeeselect2:cleared'); }, 1); };
Another to add to this post, is that this form is an ajax call: