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

allowClear with multiple="multiple" triggers a 'change' on every item cleared. #3773

Closed
vans163 opened this issue Sep 16, 2015 · 6 comments
Closed

Comments

@vans163
Copy link

vans163 commented Sep 16, 2015

If you clear a multiple select with say 5 items. change event will trigger 6 times. 1 for each item cleared and once for finalization. This is on firefox.

The problem is line 1714: this.trigger('unselect', unselectData); apparently unselect triggers the change event.

Possible fixes are comment out this line as it looks useless.
Another fix is to trigger a custom event called unselect-select2 for example to not trigger the change event.
Another fix is to rewrite change event to be called change-select2 and bind that, but this needs to be propogated throughtout the code.

@vans163 vans163 changed the title allowClear with multiple triggers change on every item cleared. allowClear with multiple="multiple" triggers a 'change' on every item cleared. Sep 16, 2015
@apbeilchick
Copy link

Same thing is happening in IE11. Also, after invoking the "clear all", the dropdown list appears without adding the select-container--focus class

@gracedigital
Copy link

Using select2 4.0.3 from CDN. I've created a multi-select via HTML and initialized it via javascript where multiple options are selected. However if I clear one of the selected options they all clear. Is there a fix or work around for this?

@alexweissman
Copy link
Contributor

This issue is solved as of 4.0.6-rc.0 (see #5058 (comment)).

@al
Copy link

al commented Aug 14, 2021

Apologies for commenting on such an old issue but I'm seeing the above behaviour on 4.0.13 (select2.full.js), i.e. multiple change events being fired in response to clearing a multiple select.

As this has been marked as resolved I just wanted to clarify whether or not it is considered a bug?

In my scenario I'd just like to submit a form on change and would like to keep that logic generic rather than have to worry about whether the event is coming from Select2 or otherwise have to intercept and handle Select2 specific events.

$form.on('change', 'select, input', (event) => {...})

Does it deserve a new issue or have I missed something maybe?

@Narghor
Copy link

Narghor commented Jan 24, 2022

Hello

I have the same problems with the latest release.
Change event is firing for each item cleared ...

How can we prevent this ?

@Mckill3r
Copy link

I have the same issue with 4.1.0-rc.0

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

8 participants