jquery - Limit select2 selections by group? -


has come way limit select2's selection group?

i'm hoping auto-remove selection same group once group selected (effectively limiting 1 selection per group)

i'll working on , post here if nobody posts solution before i'm finished.

it possible prevent selections being made in select2, can done depending on how "group" defined. if "group" <optgroup> in standard <select>, it's matter of checking see if other options in <optgroup> have been selected, , prevent in-progress selection based on that.

select2 emits select2:selecting event when selection being made, , event can prevented calling preventdefault() on it.

$("#myselect").on("select2:selecting", function (evt) {   var data = evt.params.data;   var $element = $(data.element);    // check if options in group selected   if ($element.parent("optgroup").find(":selected").length) {     evt.preventdefault();   } }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -