Why the onchange event doens’t works? I try with registerJs too
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id',
'nome',
'email:email',
'funcao',
'nomeFantasia',
[
'label' => 'Ativo newsletter',
'attribute' => 'ativo_newsletter',
'format' => 'raw',
'value' => function($model, $key, $index, $column) {
return BaseHtml::activeCheckbox($model, 'ativo_newsletter',
[
'label' => false,
'id' => 'checkbox-newsletter-'.$model->id,
'class' => 'checkbox-newsletter',
'data-id' => $model->id,
'onchange' => 'alert("hello");'
]);
}
],
['class' => 'yii\grid\ActionColumn','template' => '{view}'],
],
]); ?>
<?php
$this->registerJs('
$(".checkbox-newsletter").change(function(){
console.log($(this));
$.ajax({
method: "POST",
url: "'.Url::to(['/financeiro_legado/finlegado-pessoa-contato/update']). '",
data: {$(this).data("id")},
success: function(retorno){
console.log(retorno);
}
});
});
');
?>