kartik-v / yii2-widget-select2

Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/select2
Other
323 stars 145 forks source link

Select2 error when using plugin option "allowClear" #364

Open SegaSh99 opened 6 months ago

SegaSh99 commented 6 months ago

Prerequisites

Steps to reproduce the issue

Create a Select2 filter with the "allowClear" plugin option and without "placeholder" option. Example:

<?= $form->field($model, 'attribute')->widget(Select2::class, ([
    'data' => [1 => 1, 2 => 2],
    'pluginOptions' => [
        'allowClear' => true,
     ],
])) ?>

Expected behavior and actual behavior

When I follow those steps, I see the following error in the console:

Uncaught TypeError: Cannot read properties of undefined (reading 'id')
    at AllowClear._handleClear (select2.full.js:1907:40)
    at DecoratedClass._handleClear (select2.full.js:598:32)
    at HTMLSpanElement.<anonymous> (select2.full.js:1881:14)
    at HTMLSpanElement.dispatch (jquery.js:5145:27)
    at elemData.handle (jquery.js:4949:28)

I was expecting: the Select2 field will be cleared.

Environment

Browsers

Operating System

Libraries

Isolating the problem