Has anyone come up with a way to limit select2's selection by group?
I'm hoping to auto-remove any selection from the same group once something from that group is selected (effectively limiting to one selection per group)
I'll be working on something and will post it here if nobody posts a good solution before I'm finished.
Kevin Brown's answer was very close to what I was looking for, but I actually wanted to auto-deselect any selected options from the same optgroup. I got it working with the following:
$("#my-select").on("select2-selecting", function (event) {
$(event.object.element).parent("optgroup").find(":selected").attr('selected', false);
$("#my-select").trigger('change');
});
NOTE: I'm using Select2 3.5.2