diff --git a/dist/js/bootstrap-multiselect.js b/dist/js/bootstrap-multiselect.js index 0e30981f..ceee4869 100644 --- a/dist/js/bootstrap-multiselect.js +++ b/dist/js/bootstrap-multiselect.js @@ -1371,20 +1371,20 @@ var visibleLis = $("li:not(.divider):not(.disabled):not(.multiselect-group):not(.multiselect-filter-hidden):not(.multiselect-collapisble-hidden)", this.$ul).filter(':visible'); if(justVisible) { - $('input[type="checkbox"]:enabled' , visibleLis).prop('checked', false); + $('input[type="checkbox"]:enabled,input[type="radio"]:enabled' , visibleLis).prop('checked', false); visibleLis.removeClass(this.options.selectedClass); - $('input[type="checkbox"]:enabled' , visibleLis).each($.proxy(function(index, element) { + $('input[type="checkbox"]:enabled,input[type="radio"]:enabled' , visibleLis).each($.proxy(function(index, element) { var value = $(element).val(); var option = this.getOptionByValue(value); $(option).prop('selected', false); }, this)); } else { - $('input[type="checkbox"]:enabled' , allLis).prop('checked', false); + $('input[type="checkbox"]:enabled,input[type="radio"]:enabled' , allLis).prop('checked', false); allLis.removeClass(this.options.selectedClass); - $('input[type="checkbox"]:enabled' , allLis).each($.proxy(function(index, element) { + $('input[type="checkbox"]:enabled,input[type="radio"]:enabled' , allLis).each($.proxy(function(index, element) { var value = $(element).val(); var option = this.getOptionByValue(value); $(option).prop('selected', false); diff --git a/tests/spec/bootstrap-multiselect.js b/tests/spec/bootstrap-multiselect.js index 44b660b2..2b3d3f0c 100644 --- a/tests/spec/bootstrap-multiselect.js +++ b/tests/spec/bootstrap-multiselect.js @@ -2283,3 +2283,62 @@ describe('Knockout Binding.', function() { expect($testArea.next().find('button.multiselect').text().trim()).toEqual('2 selected'); }); }); + +describe('Method "clearSelection" should clear selection in single mode.', function() { + beforeEach(function() { + var $select = $(''); + $select.append(''); + $select.append(''); + $select.append(''); + + $('body').append($select); + + $select.multiselect({ + buttonContainer: '
' + }); + }); + + it('Method "clearSelection" is able to clear selection.', function() { + $('#multiselect-container input[value="value-2"]').click(); + expect($('#multiselect-container input:checked').length).toBe(1); + expect($('#multiselect option:selected').length).toBe(1); + + $('#multiselect').multiselect('clearSelection'); + expect($('#multiselect-container input:checked').length).toBe(0); + }); + + afterEach(function() { + $('#multiselect').multiselect('destroy'); + $('#multiselect').remove(); + }); +}); +describe('Method "clearSelection" should clear selection in multiple mode.', function() { + beforeEach(function() { + var $select = $(''); + $select.append(''); + $select.append(''); + $select.append(''); + + $('body').append($select); + + $select.multiselect({ + buttonContainer: '
' + }); + }); + + it('Method "clearSelection" should clear selection.', function() { + $('#multiselect-container input[value="value-1"]').click(); + $('#multiselect-container input[value="value-2"]').click(); + expect($('#multiselect-container input:checked').length).toBe(2); + expect($('#multiselect option:selected').length).toBe(2); + + $('#multiselect').multiselect('clearSelection'); + expect($('#multiselect-container input:checked').length).toBe(0); + expect($('#multiselect option:selected').length).toBe(0); + }); + + afterEach(function() { + $('#multiselect').multiselect('destroy'); + $('#multiselect').remove(); + }); +});