wilsonxyz
(Wilson)
1
Hi, i tried to trigger event changed in widget kartik select2, but it cannot work.
please help.
here is my codes.
<?= $form->field($detail, "[{$i}]item_id")->widget(Select2::class, [
'data' => ArrayHelper::map(\app\models\ItemSparepart::find()->where(['listed' => 1])->all(), 'id', 'name'),
'language' => 'en',
'options' => ['placeholder' => 'Select item ...'],
'pluginOptions' => [
'allowClear' => true,
],
'pluginEvents' => [
"change" => "function() { log('change'); }",
],
]) ?>
I looked into browser’s console, and it was nothing happen.
evstevemd
(Stefano Mtangoo)
2
<?= $form->field($model, 'field')->widget(Select2::class, [
'data' => ....,
'options' => [
'placeholder' => Yii::t('app', 'Select Item'),
'id' => 'my-id'
],
'pluginOptions' => [
'allowClear' => true,
],
'pluginEvents' => [
'select2:select' => 'function(e){ }',
'select2:unselect' => 'function(e){ }',
]
]) ?>
1 Like
wilsonxyz
(Wilson)
3
I have tried this code, and still not working
'pluginEvents' => [
'select2:select' => 'function(e){
alert($(this).val());
}',
],
evstevemd
(Stefano Mtangoo)
4
Alert does not get displayed? Is there an error in developer console?
wilsonxyz
(Wilson)
5
not working. i tried these way and worked
'options' => [
'placeholder' => 'Select item ...',
"onChange" => "{
//alert($(this).val());
$.get('/item-sparepart/list-stock/id='+$(this).val(), function(data) {
$('select#models-contact').html(data);
});
}"
],