Skip to content

Commit 79c8a70

Browse files
authored
Merge pull request #1162 from s-eckard/master
Fix disabledText option which was displayed for enabled dropdowns
2 parents 1866604 + b724c43 commit 79c8a70

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

dist/js/bootstrap-multiselect.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,35 +248,33 @@
248248
* @param {jQuery} select
249249
* @returns {String}
250250
*/
251-
buttonText: function (options, select) {
252-
if (this.disabledText.length > 0
253-
&& (select.prop('disabled') || (options.length == 0 && this.disableIfEmpty))) {
254-
251+
buttonText: function (selectedOptions, select) {
252+
if (this.disabledText.length > 0 && select.prop('disabled')) {
255253
return this.disabledText;
256254
}
257-
else if (options.length === 0) {
255+
else if (selectedOptions.length === 0) {
258256
return this.nonSelectedText;
259257
}
260258
else if (this.allSelectedText
261-
&& options.length === $('option', $(select)).length
259+
&& selectedOptions.length === $('option', $(select)).length
262260
&& $('option', $(select)).length !== 1
263261
&& this.multiple) {
264262

265263
if (this.selectAllNumber) {
266-
return this.allSelectedText + ' (' + options.length + ')';
264+
return this.allSelectedText + ' (' + selectedOptions.length + ')';
267265
}
268266
else {
269267
return this.allSelectedText;
270268
}
271269
}
272-
else if (this.numberDisplayed != 0 && options.length > this.numberDisplayed) {
273-
return options.length + ' ' + this.nSelectedText;
270+
else if (this.numberDisplayed != 0 && selectedOptions.length > this.numberDisplayed) {
271+
return selectedOptions.length + ' ' + this.nSelectedText;
274272
}
275273
else {
276274
var selected = '';
277275
var delimiter = this.delimiterText;
278276

279-
options.each(function () {
277+
selectedOptions.each(function () {
280278
var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).text();
281279
selected += label + delimiter;
282280
});
@@ -1617,6 +1615,8 @@
16171615
this.$select.prop('disabled', false);
16181616
this.$button.prop('disabled', false)
16191617
.removeClass('disabled');
1618+
1619+
this.updateButtonText();
16201620
},
16211621

16221622
/**
@@ -1626,6 +1626,8 @@
16261626
this.$select.prop('disabled', true);
16271627
this.$button.prop('disabled', true)
16281628
.addClass('disabled');
1629+
1630+
this.updateButtonText();
16291631
},
16301632

16311633
/**

dist/js/bootstrap-multiselect.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/spec/bootstrap-multiselect.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ describe('Bootstrap Multiselect "Core".', function() {
2323
},
2424
checkboxName: function($option) {
2525
return 'value-' + $($option).attr('value');
26-
}
26+
},
27+
disabledText: "Disabled"
2728
});
2829
});
2930

@@ -110,6 +111,7 @@ describe('Bootstrap Multiselect "Core".', function() {
110111
$('#multiselect').multiselect('disable');
111112

112113
expect($('#multiselect').prop('disabled')).toBe(true);
114+
expect($('#multiselect-container button .multiselect-selected-text').text()).toBe('Disabled');
113115
});
114116

115117
it('Should be able to enable the multiselect', function() {
@@ -415,7 +417,7 @@ describe('Bootstrap Multiselect "Single Selection".', function() {
415417

416418
describe('Bootstrap Multiselect "Individual Configuration Options".', function() {
417419

418-
describe('disableIfEmpty.', function() {
420+
describe('disableIfEmpty without options.', function() {
419421

420422
var $select = null;
421423
beforeEach(function() {
@@ -425,12 +427,14 @@ describe('Bootstrap Multiselect "Individual Configuration Options".', function()
425427

426428
$select.multiselect({
427429
buttonContainer: '<div id="multiselect-container"></div>',
428-
disableIfEmpty: true
430+
disableIfEmpty: true,
431+
disabledText: 'Disabled'
429432
});
430433
});
431434

432-
it('Should disable button if emppty.', function() {
435+
it('Should disable button if empty.', function() {
433436
expect($('#multiselect-container button').prop('disabled')).toBe(true);
437+
expect($('#multiselect-container button .multiselect-selected-text').text()).toBe('Disabled');
434438
});
435439

436440
it('Should still be disabled after invoking rebuild.', function() {
@@ -461,6 +465,35 @@ describe('Bootstrap Multiselect "Individual Configuration Options".', function()
461465
$('#multiselect').remove();
462466
});
463467
});
468+
469+
describe('disableIfEmpty with options.', function() {
470+
471+
var $select = null;
472+
beforeEach(function() {
473+
$select = $('<select id="multiselect" multiple="multiple"></select>');
474+
$select.append('<option value="value-1">Option 1</option>');
475+
$select.append('<option value="value-2">Option 2</option>');
476+
$select.append('<option value="value-3">Option 3</option>');
477+
478+
$('body').append($select);
479+
480+
$select.multiselect({
481+
buttonContainer: '<div id="multiselect-container"></div>',
482+
disableIfEmpty: true,
483+
nonSelectedText: 'Enabled'
484+
});
485+
});
486+
487+
it('Should enable button.', function() {
488+
expect($('#multiselect-container button').prop('disabled')).toBe(false);
489+
expect($('#multiselect-container button .multiselect-selected-text').text()).toBe('Enabled');
490+
});
491+
492+
afterEach(function() {
493+
$('#multiselect').multiselect('destroy');
494+
$('#multiselect').remove();
495+
});
496+
});
464497
});
465498

466499
describe('Bootstrap Multiselect "individual Methods".', function() {

tests/spec/bootstrap-multiselect.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)