diff options
author | lou <louiscuny@gmail.com> | 2013-06-28 13:01:30 +0200 |
---|---|---|
committer | lou <louiscuny@gmail.com> | 2013-06-28 13:01:30 +0200 |
commit | c417ae90f40addecfa90639b65345afe76251498 (patch) | |
tree | f752f6f54c6cef978220206437cf9c62bbb1b6fe /js/jquery.multi-select.js | |
parent | a68070e11a8bbc3fd6ff8cbe289a868343ea421a (diff) | |
download | multi-select-c417ae90f40addecfa90639b65345afe76251498.zip multi-select-c417ae90f40addecfa90639b65345afe76251498.tar.gz multi-select-c417ae90f40addecfa90639b65345afe76251498.tar.bz2 |
prevent disabled options from being selected
Diffstat (limited to 'js/jquery.multi-select.js')
-rw-r--r-- | js/jquery.multi-select.js | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index eb1f4cb..7108ef4 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -63,12 +63,12 @@ if (that.options.selectableOptgroup){ optgroupSelectableLi.on('click', function(){ - var values = optgroup.children(':not(:selected)').map(function(){ return $(this).val(); }).get(); + var values = optgroup.children(':not(:selected):not(:disabled)').map(function(){ return $(this).val(); }).get(); that.select(values); }); optgroupSelectionLi.on('click', function(){ - var values = optgroup.children(':selected').map(function(){ return $(this).val(); }).get(); + var values = optgroup.children(':selected:not(:disabled)').map(function(){ return $(this).val(); }).get(); that.deselect(values); }); } @@ -122,13 +122,8 @@ that.$selectionUl.find('.ms-optgroup-label').hide(); if ($(this).prop('disabled') || ms.prop('disabled')){ - if (this.selected) { - selectedLi.prop('disabled', true); - selectedLi.addClass(that.options.disabledClass); - } else { - selectableLi.prop('disabled', true); - selectableLi.addClass(that.options.disabledClass); - } + selectedLi.addClass(that.options.disabledClass); + selectableLi.addClass(that.options.disabledClass); } if (optgroupId){ @@ -335,8 +330,8 @@ ms = this.$element, msIds = $.map(value, function(val){ return(that.sanitize(val, that.sanitizeRegexp)); }), selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable').filter(':not(.'+that.options.disabledClass+')'), - selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection'), - options = ms.find('option').filter(function(){ return($.inArray(this.value, value) > -1); }); + selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection').filter(':not(.'+that.options.disabledClass+')'), + options = ms.find('option:not(:disabled)').filter(function(){ return($.inArray(this.value, value) > -1); }); if (selectables.length > 0){ selectables.addClass('ms-selected').hide(); @@ -412,11 +407,11 @@ var ms = this.$element, values = ms.val(); - ms.find('option').prop('selected', true); - this.$selectableUl.find('.ms-elem-selectable').addClass('ms-selected').hide(); + ms.find('option:not(":disabled")').prop('selected', true); + this.$selectableUl.find('.ms-elem-selectable').filter(':not(.'+this.options.disabledClass+')').addClass('ms-selected').hide(); this.$selectionUl.find('.ms-optgroup-label').show(); this.$selectableUl.find('.ms-optgroup-label').hide(); - this.$selectionUl.find('.ms-elem-selection').addClass('ms-selected').show(); + this.$selectionUl.find('.ms-elem-selection').filter(':not(.'+this.options.disabledClass+')').addClass('ms-selected').show(); this.$selectionUl.focus(); ms.trigger('change'); if (typeof this.options.afterSelect === 'function') { |