activeCheckbox with onchange event

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);

                     }

                 });

            });

        ');

    ?>

The onchange event looks fine. Does your console show any errors?

No, without any errors.

Are you sure that the event if it is launching?

You can check the debbuger console?

yes! I wanna update value from model when checkbox change status.