How to trigger on change/select event in DatePicker Widget

I am using yii2 DatePicker Widget. It is working correctly. But I want to trigger onchange or onselect event on change of date. I am using following code but onchange event doesnot trigger.

<?php echo \yii\jui\DatePicker::widget([





                                'clientEvents' => [

                                    'change' => 'function () { alert(\'event "change" occured.\'); }',



Please correct me where I am making mistake.

Thank you

Are you sure that you have not other javascript errors in the page? Debug it with browser.

Because the code seems good.

Yes I am sure, No javascript error. I can see even javascript code like below in script tag

jQuery(document).ready(function () {

jQuery('#w0-container').datepicker({"minDate":"0","defaultDate":null,"altField":"#w0","dateFormat":"M d, yy"});

jQuery('#w0-container').on('datepickerchange', function () { alert('event "change" occured.'); });

But on change of date, no alert. I think something is missing but not getting what is that.

This line is wrong:

jQuery('#w0-container').on('datepickerchange', function () { alert('event "change" occured.'); });

it should be:

jQuery('#w0-container').on('change', function () { alert('event "change" occured.'); });

Yes It should be "change" in place of "datepickerchange". I have set "change" but it appends widget name. How can set exactly "Change"

Anybody have tried to solve. I have been stucked into it.

Looks like there are no events for Datepicker

But you can use onSelect option

'clientOptions' => [

    'onSelect' => new \yii\web\JsExpression('function(dateText, inst) { console.log(dateText, inst) }'),


Thanks again Bizley. You solved my issue. Thank you so much

Hi Bizley

I’m trying something like this

'onClose' => 'js:function(selectedDate){ 

          $("#fechafinal").datepicker("option", "minDate", selectedDate);


But in Yii2 no work, I’m use Datepicker Dosamigos.

Can you help?

There is ‘clientEvents’ parameter and then there is this ‘hide’ event. I have not seen ‘close’ event there so ‘hide’ should do the trick.