Select2: Multiple select (checkboxes and/or toggleStates)

Created on 13 Sep 2012  Â·  60Comments  Â·  Source: select2/select2

Is there any intention to incorporate a standard multiple select drop down with checkboxes / toggle states at any point? - Specifically like this -> http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/

It would be nice to have as a core option without hacking around the formatting with injected checkboxes and custom event handlers to catch the behaviours needed with the current select2 library.

Cheers,

  • D

Most helpful comment

For those who are still looking for a solution, have a look at my fiddle.

I have used a couple of fiddles posted about the question and combined it all into 1

Not perfect, but it works.

https://jsfiddle.net/Lkkm2L48/7/

All 60 comments

you are welcome to provide a pull request and if it doesnt make things too messy i may commit it. the main problem, and why i have not done it yet, is that select2's primary usecase is working with large remote datasets - so checkboxes do not really make sense.

I figured as much :)

It would be straight forward to implement a toggle / checkbox based multiple select by default but keeping it clean with the current multiple select class might be a little trickier, I'll put a request through, the simplest solution would be to supply a set of secondary arguments in a data attribute to define the type of 'multiselect' you would like with the way the script is currently written :)

I'll have a dig at work tomo.

Cheers,
Dan

@danjme Did you ever give this a shot?

@ivaynberg First and foremost, I love Select2. Great work. It's hands-down my dropdown library of choice.

Though I understand your reasoning for not having implemented checkboxes up to this point, this seems to be a very common request/inquiry from your users (I found at least 5 references in the issues).

I too would love to see checkboxes added to Select2. I've been forced to switch to Eric Hynd's multiselect widget on a number of consulting projects, simply because the client decides checkboxes "make more sense" for them. Don't get me wrong, Eric's work is great also, but if I'm already using Select2 everywhere else on the site, having to switch to a different library (just to have checkboxes on a couple of drop-downs) is quite the inconvenience and time sink.

So, even though it doesn't necessarily align with the original use-case, I strongly believe checkboxes would be both a practical and convenient addition to Select2.

Having said all of that, I completely understand that this is easier said than done.

How much complexity would this add?
Is it a huge development effort?

Lastly, is this something you would consider doing if I could gather up some funds to make a small donation to the project?

Thanks and best regards!
-Nestor

I agree. My users are using it to filter data and they sometimes want to be able to select 10 items or more. I've had to use Eric Hynd's multiselect in cases like this because Select2's tag style is too bulky for more than a few selections.

I did customise the select2 library to support this, I'll submit a pull request to submit my contributions

Sent from my iPhone

On 23 Aug 2013, at 16:03, "homer2" <[email protected]notifications@github.com> wrote:

I agree. My users are using it to filter data and they sometimes want to be able to select 10 items or more. I've had to use Eric Hynd's multiselect in cases like this because Select2's tag style is too bulky for more than a few selections.

—
Reply to this email directly or view it on GitHubhttps://github.com/ivaynberg/select2/issues/411#issuecomment-23167664.

I would definitely like to have this feature.

Any updates on this pls?

@danjme, did you ever submit the pull request?

@danjme Do you need any help to implement this issue? I'm really in need of it. Should I start to do by myself or have you alredy started? Tks.

@danjme same as above. I'm a great fan of select2 and need to implement that exact functionality... can you submit your code? I would also be available to help implement it...

@danjme +1 for this pull request

+1

+100000

+1

+1

Throwing this in the list for 4.0, which should make it considerably easier to implement as a plugin.

Sounds good!

I'm excited about the prospect of this being implemented, thanks guys!

For people who still want the checkbox list functionality in the current version (before 4.0), I managed to have it working. This version has checkboxes as images, but I'm pretty sure it can be made to work with real checkboxes with some tweaking. Check it out: http://jsfiddle.net/6dd2gj8d/3/
Note that this is using the closeOnSelect: false setting, and because of #2783 the highlighting/selecting with the up and down arrow keys doesn't work in the current version

Has this enhancement been implemented? I'm looking at Version 4.0.0-beta.3 and I don't see it.

This is possible to do now by either styling selected options ([aria-selected=true]) or overriding the resultsAdapter and adding some more logic when rendering the results.

Has this enhancement been implemented? Can anyone tell how to use this enhancement.

Hi, take a look into this: http://jsfiddle.net/wasikuss/cg1zr4zd/
I know that function onSelect is broken, but it is ok for simple usage :)

I'm going to finish this and make fully compatible plugin that adds new functions without altering default behaviour.

@kevin-brown are there any examples of overriding the resultsAdapter? I've looked in the Docs and the Forum but i can't see anything.

If this is still a thing, can this issue get reopened? And if not, can you clearly say so?

Looks like you can get half way there without a custom adapter by just overriding the template for results.

http://jsbin.com/wezudobake/1/

Nice, but it would be great if we could get some extra features as

  • grouping (category1 with some sub-elements, category2 with some sub-elements, etc..)
  • selecting multiple sub-elements with a single click on their parent (group)
  • (un)expanding groups (show/hide all sub-elements in a group)

Basically, something like this

@kevin-brown, in your example of overriding the template, if CloseOnSelect is set to false, clicking outside of the checkbox will select the item but not check the checkbox.
http://jsbin.com/tifuzikimo/edit?html,js,output

Also, the templateSelection is still tag based. That is fine for a few items, but when dozens of items are selected it could be too much. Showing a summary instead would be nice, like "21 of 100 selected".

erichynds jquery-ui-multiselect-widget takes this idea a step further by showing either the selected items or the summary based on the number of item selected: "Alabama, Florida, Georgia" or "48 of 50 selected"

Anyway, I think @wasikuss's example is the kind of functionality were looking for.

@homer2 the example from @wasikuss is a nice example but is not going to work on multiple select boxes on the page selected by a class. The code needs some alteration for multiple select boxes.

See this fiddle:
http://jsfiddle.net/mL44s7rr/

@PlippiePlop,
It also work on class-selected elements

http://jsfiddle.net/wasikuss/gx93rwnk/

@wasikuss ah I see what I did wrong. Thank you for the insight ;)

+1

+1

+1

Any news on this?

+1
Please integrate the checkboxes into main version, the tags are useless with lots of elements selected

+1

+1

For anyone coming here from google and/or interested, check https://github.com/alexandernst/angular-multi-select for a good multi select.

For anyone that would want a simple CSS solution to this :
http://codepen.io/stephenbe/pen/zBrzYP

Just change the background color to a background image of a checkbox.

Cheers

@wasikuss did you ever make a plugin for this?

Ok, I see more and more ppl need that plugin. I will post link to plugin when it's done ( 2 - 3days ).

+1, tags are not needed in every case. Moreover, fast group selection is desired too.

+1

https://github.com/wasikuss/select2-multi-checkboxes
Please try and feel free to report any bugs/features.

Cheers

+1

The select2 that I'm converting to multi-select includes an up/down arrow on the far right, a magnifying glass search icon on the far right in the search input box, and a scrollbar on the right of the dropdown.
select2-with-search

Is it possible to incorporate these three styles into the third 'select2-original' option please?

just remove line 44 in select2.multi-checkboxes.js ;)

Setting minimumResultsForSearch: 0 shows the search box for the first 2 dropdowns which is nice, thank you. However it doesn't change the 3rd option where the selected names appear at the top. There seems to be a search box there without border, it would be great if the border, magnifying glass image, up/down arrow, and vertical scroll could be incorporated into the 3rd layout option.

The select all option shown here taken from here was a very useful addition.

Hi @wasikuss , was checking your plugin and it's almost what I need but i see it's working with select2 3.5.2. Did your ever upgrade the code to v4?
Thanks in advance,

This issue is closed- has it been implemented already?

Great,
This was what I was looking for also.

@zakamik Yes, repo is here:
https://github.com/wasikuss/select2-multi-checkboxes

For those who are still looking for a solution, have a look at my fiddle.

I have used a couple of fiddles posted about the question and combined it all into 1

Not perfect, but it works.

https://jsfiddle.net/Lkkm2L48/7/

@WillemOpperman works great, but only issue that it does not work when you have multiple selects on the screen. it should work with multiple selects on class or id base. See https://jsfiddle.net/nzfhkfuk/2

@WillemOpperman looks good except it always jumps to first selection each time you select.

@kevin-brown @alexweissman I still think this shouldn't be closed, and should be implemented officially. The select2-multi-checkboxes has issues, and dev is not responding. So basically this is still unsolved after years, which is so sad, because select2-multi-checkboxes almost solved this issue perfectly with only ~70 lines of code. Anyway, thanks for trying to keep the project alive!

sorry for late response but it is already done. This time properly - less ugly hacks that previously broke partially select2 API.

https://github.com/wasikuss/select2-multi-checkboxes/tree/amd

so the feature was requested but the case was close to use select2?

+1 !

That's how I solved this problem.

https://jsfiddle.net/akwud47t/1/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

videsignz picture videsignz  Â·  3Comments

dnohr picture dnohr  Â·  3Comments

pbkracker picture pbkracker  Â·  3Comments

mauroschiappo picture mauroschiappo  Â·  3Comments

ghost picture ghost  Â·  3Comments