open select2 prevents click event on button

2,271 views
Skip to the first unread message

gert.g...@gmail.com

unread,
13 Jan 2015, 05:17:0613/01/2015
to sel...@googlegroups.com
Hi all,

My situation: I have a multi-select select2 list that I keep open while the user picks some options. When I, with open list, click on my Apply button, I want the list to close AND the button's click event to fire.

I've noticed that this doesn't work because the list closes, but the click event of the button never fires - presumably because the select2 code kills it. The one event that does get triggered on the button (with open list) is mouseup. So my work-around is to use mouseup instead of click. Not ideal, but more or less acceptable.

A fiddle showing the issue: http://jsfiddle.net/GertG/0990t51L/26/

My questions:
1 Is there a more proper way around this with the current version of select2 than resorting to the mouseup event?
2 Is this behavior intentional and should I assume that select2 is always going to prevent click events that cause a select2 list to close to propagate to the actual control that was clicked?
3 Is the exclusion of mouseup an oversight and are future versions therefor likely to break my work-around?


I'd appreciate any help or insights.
Gert

Kevin Brown

unread,
13 Jan 2015, 13:14:1513/01/2015
to sel...@googlegroups.com
Hi Gert,

This is a common issue for those using Select2 3.x, as we switched to a
click mask to ensure that the background is closed. You can find more
information on the discussion around the choice at the following ticket:

https://github.com/select2/select2/issues/873

> I've noticed that this doesn't work because the list closes, but the click event of the button never fires - presumably because the select2 code kills it. The one event that does get triggered on the button (with open list) is mouseup. So my work-around is to use mouseup instead of click. Not ideal, but more or less acceptable.

The issue is that there is another element sitting in between the button
and the mouse which is catching the event.

> 1. Is there a more proper way around this with the current version of select2 than resorting to the mouseup event?

Select2 4.0 fixes this by giving you an option of using the click event
instead of the click mask. By default we no longer use the click mask.

> 2. Is this behavior intentional and should I assume that select2 is always going to prevent click events that cause a select2 list to close to propagate to the actual control that was clicked?

In Select2 3.5.x, you can assume that Select2 is always going to stop
any click events that would otherwise close the dropdown.

> 3. Is the exclusion of mouseup an oversight and are future versions therefor likely to break my work-around?

See above.

Kevin Brown

Gert Gielen

unread,
19 Jan 2015, 03:47:5119/01/2015
to sel...@googlegroups.com
Thank you for the clarifying answer, Kevin.
At least I understand now what's happening and why.

Regards,
Gert

ankita bhatt

unread,
28 Sept 2017, 02:01:0928/09/2017
to select2
Hii Kevin,

Can you tell me how can i perform


1. Is there a more proper way around this with the current version of select2 than resorting to the mouseup event?

Select2 4.0 fixes this by giving you an option of using the click event
instead of the click mask. By default we no longer use the click mask.


Waiting for your reply.

Regards, Ankita
Reply all
Reply to author
Forward
0 new messages