JQuery Select2 - How to select all options -
i'm using jquery select2 multi select dropdown. need select options in dropdown code. there select checkbox on functionality has implemented, want select/deselect options checkbox.
there description in thread on github. quoting (https://github.com/ivaynberg/select2/issues/195#issuecomment-13489140 mortadaak) allows select on ctrl+a
$(document).on("keypress",".select2-input",function(event){ if (event.ctrlkey || event.metakey) { var id =$(this).parents("div[class*='select2-container']").attr("id").replace("s2id_",""); var element =$("#"+id); if (event.which == 97){ var selected = []; element.find("option").each(function(i,e){ selected[selected.length]=$(e).attr("value"); }); element.select2("val", selected); } else if (event.which == 100){ element.select2("val", ""); } } });
Comments
Post a Comment