2amigos / yii2-date-picker-widget

Bootstrap DatePicker Widget for Yii2
https://2amigos.us
Other
130 stars 77 forks source link

Clear button problem #48

Closed dmdb closed 7 years ago

dmdb commented 7 years ago

Can't figure out how clear button works. Using simple configuration of widget in GridView filter:

    <?php Pjax::begin(); ?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'email:email',
            'created_at:datetime',
            [
                'attribute' => 'last_login',
                'format' => 'datetime',
                'filter' => DatePicker::widget([
                    'model' => $searchModel,
                    'attribute' => 'last_login',
                    'template' => '{addon}{input}',
                    'clientOptions' => [
                        'autoclose' => true,
                        'format' => 'yyyy-mm-dd',
                        'clearBtn' => true,
                    ],
                ])
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
    <?php Pjax::end(); ?>

Pushing clear does'nt reload GridView. Inputs val() clears, but actual attribute value - not. It seems that none of change event is firing also. Am I miss something simple? In other parts widget works just great.

tonydspaniard commented 7 years ago

@dmdb I think the issue is because you are using Pjax. Can you try without pjax widget? If that solves the issue, then you will surely have to work a bit further your code to make it work in conjunction with Pjax, like reinitializing the widget and so on...

dmdb commented 7 years ago

@tonydspaniard Nope. Removed Pjax and got same. Forcing change event trigger on input after pushing clear button works fine. Solved this via "clientEvents" widget property

            'clientEvents' => [
                'clearDate' => 'function (e) {$(e.target).find("input").change();}',
            ],

Not sure that this way is right way to handle widget usage in filters. But it works, also with Pjax.

tonydspaniard commented 7 years ago

@dmdb Thank you very much for pointing that out and happy you found the way to solve the issue.