Skip to content

Commit

Permalink
Merge pull request #5 from MalikAtalla-AI/2005
Browse files Browse the repository at this point in the history
WI-2005 Bugfix: deselectAll doesn't deselect radion buttons
  • Loading branch information
JesseChezenko-AI authored Sep 19, 2016
2 parents d93739f + d69bb8e commit 3007329
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dist/js/bootstrap-multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
59 changes: 59 additions & 0 deletions tests/spec/bootstrap-multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 id="multiselect"></select>');
$select.append('<option value="value-1">Option 1</option>');
$select.append('<option value="value-2">Option 2</option>');
$select.append('<option value="value-3">Option 3</option>');

$('body').append($select);

$select.multiselect({
buttonContainer: '<div id="multiselect-container"></div>'
});
});

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 id="multiselect" multiple="multiple"></select>');
$select.append('<option value="value-1">Option 1</option>');
$select.append('<option value="value-2">Option 2</option>');
$select.append('<option value="value-3">Option 3</option>');

$('body').append($select);

$select.multiselect({
buttonContainer: '<div id="multiselect-container"></div>'
});
});

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();
});
});

0 comments on commit 3007329

Please sign in to comment.