Datapicker widget insert calback javascript

Hi,

I’m starting to use yii 2 and I have this problem:




echo DatePicker::widget([

    'language' => 'it',

    'name'  => 'id1',

    'id' =>'id1',

    'clientOptions' => [

        'dateFormat' => 'dd-mm-yy',

        'minDate'=>'today',

       'onSelect' => 'function(){alert("Date selected!")}'


        

    ],

]);

I have 1 javascript error (undefined is not a function) onSelect, why?

sorry for my english.

I think you need to add required namespace

e.g before using Gridview we use


use yii\grid\GridView;

If Javed is correct, the use statement is:

use yii\jui\DatePicker;

If that is not included in the view, it will cause problems. I found the DatePicker to be buggy. I couldn’t get it to respect the dateFormat, see this post, so I ended up having to write a beforeValidate filter on the model to translate it. I’m curious to see how it goes for you and to see if onSelect is supported correctly by the widget.