From b92beb4cd9ba9b18d4788b0a99a884dbf519d7f0 Mon Sep 17 00:00:00 2001 From: abuzer-firdousi-confiz Date: Thu, 4 Jun 2015 17:38:35 +0500 Subject: [PATCH] added max selection variable check --- js/ui.multiselect.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/js/ui.multiselect.js b/js/ui.multiselect.js index 3f653d8..d81f946 100755 --- a/js/ui.multiselect.js +++ b/js/ui.multiselect.js @@ -35,6 +35,7 @@ $.widget("ui.multiselect", { animated: 'fast', show: 'slideDown', hide: 'slideUp', + maxSelection: 0, dividerLocation: 0.6, availableFirst: false, nodeComparator: function(node1,node2) { @@ -266,8 +267,8 @@ $.widget("ui.multiselect", { elements.find('a.action').click(); } }); - }, - _registerHoverEvents: function(elements) { + } +, _registerHoverEvents: function(elements) { elements.removeClass('ui-state-hover'); elements.mouseover(function() { $(this).addClass('ui-state-hover'); @@ -279,9 +280,14 @@ $.widget("ui.multiselect", { _registerAddEvents: function(elements) { var that = this; elements.click(function() { - var item = that._setSelected($(this).parent(), true); - that.count += 1; - that._updateCount(); + if(that.options.maxSelection != 0 && ( that.count >= that.options.maxSelection )){ + that.selectedContainer.find('span.count').text('No more item cannot be added'); + }else{ + var item = that._setSelected($(this).parent(), true); + that.count += 1; + that._updateCount(); + } + return false; });