diff --git a/src/jquery.multiselect.js b/src/jquery.multiselect.js
index c389bad..cf7a7b3 100644
--- a/src/jquery.multiselect.js
+++ b/src/jquery.multiselect.js
@@ -46,7 +46,7 @@
noneSelectedText: 'Select options', // (str | null) The text to show in the button where nothing is selected. Set to null to use the native select's placeholder text.
selectedText: '# of # selected', // (str) A "template" that indicates how to show the count of selections in the button. The "#'s" are replaced by the selection count & option count.
selectedList: 0, // (int) The actual list selections will be shown in the button when the count of selections is <= than this number.
- selectedMax: null, // (int | function) If selected count > selectedMax or if function returns 1, then message is displayed, and new selection is undone.
+ maxSelected: null, // (int | null) If selected count > maxSelected, then message is displayed, and new selection is undone.
show: null, // (array) An array containing menu opening effects.
hide: null, // (array) An array containing menu closing effects.
autoOpen: false, // (true | false) If true, then the menu will be opening immediately after initialization.
@@ -104,7 +104,7 @@
var options = this.options;
var classes = options.classes;
var headerOn = options.header;
- var checkAllText = options.checkAllText;
+ var checkAllText = options.maxSelected ? null : options.checkAllText;
// Do an extend here to address icons missing from options.iconSet--missing icons default to those in defaultIcons.
var iconSet = $.extend({}, defaultIcons, options.iconSet || {});
var uncheckAllText = options.uncheckAllText;
@@ -119,10 +119,9 @@
this.speed = $.fx.speeds._default;
this._isOpen = false;
- // create a unique namespace for events that the widget
- // factory cannot unbind automatically. Use eventNamespace if on
- // jQuery UI 1.9+, and otherwise fallback to a custom string.
- this._namespaceID = this.eventNamespace || ('multiselect' + multiselectID);
+ // Create a unique namespace for events that the widget
+ // factory cannot unbind automatically.
+ this._namespaceID = this.eventNamespace.slice(1);
// bump unique ID after assigning it to the widget instance
this.multiselectID = multiselectID++;
@@ -511,6 +510,12 @@
var $inputs = $this.next('ul').find('input').filter(':visible:not(:disabled)');
var nodes = $inputs.get();
var label = this.textContent;
+
+ // if maxSelected is in use, cannot exceed it
+ var maxSelected = self.options.maxSelected;
+ if (maxSelected && (self.$inputs.filter(':checked').length + $inputs.length > maxSelected) ) {
+ return;
+ }
// trigger before callback and bail if the return is false
if (self._trigger('beforeoptgrouptoggle', e, { inputs:nodes, label:label }) === false) {
@@ -593,11 +598,10 @@
var $tags = $element.find('option');
var isMultiple = $element[0].multiple;
var $allInputs = self.$inputs;
- var inputCount = $allInputs.length;
var numChecked = $allInputs.filter(":checked").length;
var options = self.options;
var optionText = $input.parent().find("span")[options.htmlOptionText ? 'html' : 'text']();
- var selectedMax = options.selectedMax;
+ var maxSelected = options.maxSelected;
// bail if this input is disabled or the event is cancelled
if (input.disabled || self._trigger('click', e, { value: val, text: optionText, checked: checked }) === false) {
@@ -605,18 +609,10 @@
return;
}
- if ( selectedMax && checked
- && ( typeof selectedMax === 'function' ? !!selectedMax.call(input, $allInputs) : numChecked > selectedMax ) ) {
- var saveText = options.selectedText;
-
- // The following warning is shown in the button and then cleared after a second.
- options.selectedText = "