Skip to content

Commit

Permalink
improve disabled option logic - fix #1363
Browse files Browse the repository at this point in the history
address some items from #1356
  • Loading branch information
caseyjhol committed May 13, 2016
1 parent d10ccdf commit 3f106d8
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions js/bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,16 @@
tokens = $this.data('tokens') ? $this.data('tokens') : null,
subtext = typeof $this.data('subtext') !== 'undefined' ? '<small class="text-muted">' + $this.data('subtext') + '</small>' : '',
icon = typeof $this.data('icon') !== 'undefined' ? '<span class="' + that.options.iconBase + ' ' + $this.data('icon') + '"></span> ' : '',
isOptgroup = this.parentNode.tagName === 'OPTGROUP',
isDisabled = this.disabled || (isOptgroup && this.parentNode.disabled);
$parent = $this.parent(),
isOptgroup = $parent[0].tagName === 'OPTGROUP',
isOptgroupDisabled = isOptgroup && $parent[0].disabled,
isDisabled = this.disabled || isOptgroupDisabled;

if (icon !== '' && isDisabled) {
icon = '<span>' + icon + '</span>';
}

if (that.options.hideDisabled && (isDisabled && !isOptgroup || this.parentNode.disabled && isOptgroup)) {
if (that.options.hideDisabled && (isDisabled && !isOptgroup || isOptgroupDisabled)) {
liIndex--;
return;
}
Expand All @@ -577,15 +579,27 @@
}

if (isOptgroup && $this.data('divider') !== true) {
var optGroupClass = ' ' + this.parentNode.className || '';
if (that.options.hideDisabled && isDisabled) {
if ($parent.data('allOptionsDisabled') === undefined) {
var $options = $parent.children();
$parent.data('allOptionsDisabled', $options.filter(':disabled').length === $options.length);
}

if ($parent.data('allOptionsDisabled')) {
liIndex--;
return;
}
}

var optGroupClass = ' ' + $parent[0].className || '';

if ($this.index() === 0) { // Is it the first option of the optgroup?
optID += 1;

// Get the opt group label
var label = this.parentNode.label,
labelSubtext = typeof $this.parent().data('subtext') !== 'undefined' ? '<small class="text-muted">' + $this.parent().data('subtext') + '</small>' : '',
labelIcon = $this.parent().data('icon') ? '<span class="' + that.options.iconBase + ' ' + $this.parent().data('icon') + '"></span> ' : '';
var label = $parent[0].label,
labelSubtext = typeof $parent.data('subtext') !== 'undefined' ? '<small class="text-muted">' + $parent.data('subtext') + '</small>' : '',
labelIcon = $parent.data('icon') ? '<span class="' + that.options.iconBase + ' ' + $parent.data('icon') + '"></span> ' : '';

label = labelIcon + '<span class="text">' + label + labelSubtext + '</span>';

Expand Down

0 comments on commit 3f106d8

Please sign in to comment.