Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery select2 howto make dont close after select

  1. When using "Multi-Value Select Boxes" http://ivaynberg.github.io/select2/ slect box drop back after each selection. Is there the way not to do it, so user can select few of it without extra click to select box?

  2. Also interested in group options. In demo url above, "Pasific Time Zone", "Mountain Time Zone" not clickable. How to make it clickable and autoselect child items?

like image 351
smbhere Avatar asked Oct 16 '14 02:10

smbhere


People also ask

How do I stop select2 from auto selecting the first option?

This behaviour exists not because Select2 is forcing it, but because the browser is auto-selecting the first option for you. We can't control that, we can only work around it. Your best option is to use the placeholder support in Select2 and include a blank option tag as your default selection.

How do I set select2 to readonly?

$(element). select2('destroy'). attr("readonly", true)

How do you focus Select 2?

$('#id'). select2('open'); will set focus and open the select2 ready for search. $('#id'). select2('focus'); will set the focus on select2 but not select2 will be not opened for search.


1 Answers

Question 1:

From the documentation I can see this option:

closeOnSelect: false

This option is set to true by default, meaning the select box closes on select.

So, this is a simple call of the plugin:

$('#mySelect').select2({
    closeOnSelect: false
});

Question 2:

This question is a bit vague. It's a fairly simple task, but without going through the plugin's files and understanding its logic, it's difficult to know how to answer — and I'm not spending hours trying. This is something you'll have to try yourself, as I personally don't think you'll find anyone here willing to do that for free. It's asking a little bit much.

Take a look at its files and see if you can work out what is going on and try something. People will always be willing to help if you've tried. Good luck.

like image 191
TheCarver Avatar answered Oct 22 '22 16:10

TheCarver