kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
556 stars 303 forks source link

Select2 filter with multiple and allowClear plugin option can not clear all items #951

Closed tsanchev closed 4 years ago

tsanchev commented 4 years ago

Prerequisites

Steps to reproduce the issue

Trying to creat a Select2 filter with multiple and allowClear plugin options. Everything works except when 'x' is clicked to clear all items. In the console I can see the following error:

Uncaught TypeError: Cannot read property 'id' of undefined
at DecoratedClass.AllowClear._handleClear (select2.full.js?v=1579937348:1886)
at DecoratedClass._handleClear (select2.full.js?v=1579937348:598) 
...

I'm using the following code to render the widget:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        //...
        [
            'attribute' => 'status',
            'format' => 'raw',
            'value' => function ($model) {
                /* @var $model Ticket */
                return $model->statusAsHtml;
            },

            'filter' => Ticket::ticketStatuses(),
            'filterType' => GridView::FILTER_SELECT2,
            'filterWidgetOptions' => [
                'pluginOptions' => [
                    'allowClear' => true,
                    'multiple' => true,
                    //'placeholder' => '',
                ],
            ],
        ],
        //...
    ],
]); ?>

If the placeholder plugin option is added the 'x' is working and there is no error in console window.

Environment

Browsers

Operating System

Libraries

Isolating the problem

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.