unexpected behaviour of multiple select box

53 views
Skip to first unread message

alexande...@gmail.com

unread,
Jul 30, 2015, 2:44:33 AM7/30/15
to select2
Hi There,

I find your select2 multiple select box very handy. However, there is always a "but" ;)

In your example page (https://select2.github.io/examples.html) I played around with the multiple select box and figured out, that if you select an element (accidentally) twice it disappears (unselect).

Is there a way to prevent this?

br, Alex

alexande...@gmail.com

unread,
Jul 30, 2015, 2:53:08 AM7/30/15
to select2, alexande...@gmail.com

Addition: This occurs only when selected via mouse click. With the keyboard it works fine.

Kevin Brown

unread,
Jul 30, 2015, 9:14:41 PM7/30/15
to select2, alexande...@gmail.com
This is standard, expected behaviour when working with a multiple select box.

You can select an option which is not selected using the mouse, and the option will now be selected. And you can select an option which is currently selected using the mouse, and it will now be unselected. The mouse has the ability to toggle the selection state of an option.

It's slightly different with the keyboard, because of the standard keybindings for select boxes and dropdowns. You can select any option with the ENTER key, which behaves exactly the same as selecting it with your mouse. Or you can toggle the state of an option (selected -> unselected, unselected -> selected) using the CTRL + SPACE combination. This is standard with a browser (try it out on a multiple select) and it's the standard keybinding for toggling the state of things in most operating systems. Try selecting or unselecting an option in your file manager using CTRL + SPACE and ENTER, and note how they react.

The reason for the difference in the keybindings both has to do with keybindings, but also with people holding ENTER for too long and clearing all of their selections. It's still possible with CTRL + SPACE, try selecting a bunch of options and then just holding it down until all of them become unselected. It's not a great user experience, so we took note during the betas and corrected the keybindings after doing further research.

You can prevent the unselection of any item by calling `event.preventDefault()` on any `select2:unselecting` event.

--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at http://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.

alexande...@gmail.com

unread,
Aug 3, 2015, 3:21:27 AM8/3/15
to select2, alexande...@gmail.com, ke...@kevin-brown.com
Thank you for your answer.
Reply all
Reply to author
Forward
0 new messages