From 21e528451599c1bccfb5ea11fda31bc1867282de Mon Sep 17 00:00:00 2001 From: Mosh Feu Date: Mon, 29 Aug 2016 16:05:20 +0300 Subject: [PATCH] add "limit" option With this option, you can limit the options the user can select --- js/jquery.multi-select.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index fb478f5..bd44784 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -73,7 +73,10 @@ var action = that.options.dblClick ? 'dblclick' : 'click'; that.$selectableUl.on(action, '.ms-elem-selectable', function(){ - that.select($(this).data('ms-value')); + var selectedCount = ms.find(':selected').length; + if (!that.options.limit || that.options.limit > selectedCount) { + that.select($(this).data('ms-value')); + } }); that.$selectionUl.on(action, '.ms-elem-selection', function(){ that.deselect($(this).data('ms-value')); @@ -518,7 +521,8 @@ disabledClass : 'disabled', dblClick : false, keepOrder: false, - cssClass: '' + cssClass: '', + limit: null }; $.fn.multiSelect.Constructor = MultiSelect;