Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Clear button problem #48

Closed
dmdb opened this issue Aug 3, 2017 · 3 comments
Closed

Clear button problem #48

dmdb opened this issue Aug 3, 2017 · 3 comments

Comments

@dmdb
Copy link

dmdb commented Aug 3, 2017

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
Copy link
Member

@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
Copy link
Author

dmdb commented Aug 6, 2017

@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
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants