Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select2 error when using plugin option "allowClear" #364

Open
10 of 19 tasks
SegaSh99 opened this issue Mar 21, 2024 · 0 comments
Open
10 of 19 tasks

Select2 error when using plugin option "allowClear" #364

SegaSh99 opened this issue Mar 21, 2024 · 0 comments

Comments

@SegaSh99
Copy link

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-widget-select2.
  • This is not an usage question. I confirm having read the widget documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • This is not a source plugin (select2) issue. (Those should be directed to the plugin issues repo).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

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

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 3.7.1
  • yii2-widget-select2 version: 2.2.5

Isolating the problem

  • This bug happens on the widget demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-widget-select2 without other plugins
  • I can reproduce this bug in a jsbin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant