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

Select All doesn't select elements which values contains minus '-' #330

Closed
11 of 19 tasks
deferenty opened this issue Sep 24, 2020 · 1 comment
Closed
11 of 19 tasks

Comments

@deferenty
Copy link

deferenty commented Sep 24, 2020

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
    There are two similar closed issues: 306 and 312. But the issue still exists.

  • The issue still exists against the latest master branch of yii2-widget-select2. (version 2.1.9)

  • 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

  1. Run the widget
    echo Select2::widget([ 'name' => 'state_10', 'data' => [ 'first'=>'One', 'second' => 'Two', 'thi-rd' => 'Three', 'fourth-' => 'Four'], 'options' => [ 'placeholder' => 'Select provinces ...', 'multiple' => true ], ]);

Expected behavior and actual behavior

When press 'Select all' - expecting behavior - select all options.

If some options' values have minus '-', 'Select All' doesn't select them. In the following example only 'One' and 'Two' will be selected. Even so, 'Three' and 'Four' can be selected manually one by one.

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

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

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

Workaround

Maybe this can help to resolve the issue - change 46 row of 'select2-krajee.js':

from val = $(this).attr('id').split('-').pop();
to [, val] = $(this).attr('id').match(/^select2-[^-]*-result-.{4}-(.*)$/);

@deferenty
Copy link
Author

Hello!

Thanks for such a quick hot-fix.

Now everything works fine for the case without active-form and model.

But if we use active-form and model - Select All stops working, because regex doesn't match any id. It's because with active form and model is formed like select2-modelName-fieldName-result-randomValue-id

Maybe regex should be changed to something like this ^select2-\S*-result-.{4}-(.*)$

@kartik-v kartik-v reopened this Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants