You can use the unSelectAll and selectItem as well as the triggerChangeCombined parameter in the triggerChangeCombined init.
Link: http://hemantnegi.imtqy.com/jquery.sumoselect/
In the event of a change, if the limit is increased, you can deselect all and set the last valid selection by the index of each element.
Code:
$('#island').SumoSelect({ triggerChangeCombined: true, placeholder: "TestPlaceholder" }); var last_valid_selection = null; $('#island').change(function (event) { if ($(this).val().length > 2) { alert('You can only choose 2!'); var $this = $(this); $this[0].sumo.unSelectAll(); $.each(last_valid_selection, function (i, e) { $this[0].sumo.selectItem($this.find('option[value="' + e + '"]').index()); }); } else { last_valid_selection = $(this).val(); } });
Demo: http://jsfiddle.net/IrvinDominin/80xLm01g/
source share