DatePicker widget trigger event

Hi everyone.

I have a problem with the datePicker::widget.

It’s not triggering a change(date) event.

This is my code.




<?php

  use yii\jui\DatePicker;


<?= DatePicker::widget([

    'name' => 'datepicker',

    'clientOptions' => [

        'changeMonth' => true,

        'changeYear' => true,

        'showOn' => 'both',

        'buttonImage' => 'images/calendar.gif',

        'buttonImageOnly' => false,

        'buttonText' => 'Select date',

    ],

    'clientEvents' => [

        'change' => 'function () { alert("change"); }',

    ],

]);

?>



Is there any indication on firebug’s console?

No error messages in the console.

Did you see in source code .on() event handler on your datepicker?

Hi Fabrizio,

Yes, but how can I use this in my example.

I you see .on() event handler on your datepicker, an alert window should be shown when you click on datepicker.

Are you sure that you haven’t other event handler on that datepicker?

If you try to set an event handler manually, so:




<script>

$('#mydatepicker').on('click', function() {

      alert('mydatepicker event handler!');

});



What happens?

That’s working,

I thought it was possible to use a js action inside the DatePicker widget.

Doc says that it’s possibile.

http://www.yiiframework.com/doc-2.0/yii-jui-widget.html#$clientEvents-detail

Olso for me DatePicker::widget has no reaction for clientEvents “change”, BUT …it has for CLICK!!! (4!!! as the number of hours I lost on this)

I think use must use js expression.

'change' => new \yii\web\JsExpression('function () { alert("change"); }')