Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

** Fix for #431 ** #435

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions dist/js/bootstrap-multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
ul: '<ul class="multiselect-container dropdown-menu"></ul>',
filter: '<li class="multiselect-item filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
filterClearBtn: '<span class="input-group-btn"><button class="btn btn-default multiselect-clear-filter" type="button"><i class="glyphicon glyphicon-remove-circle"></i></button></span>',
li: '<li><a href="javascript:void(0);"><label></label></a></li>',
li: '<li><a tabindex="0"><label></label></a></li>',
divider: '<li class="multiselect-item divider"></li>',
liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
}
Expand Down Expand Up @@ -451,19 +451,24 @@
}
}, this));

$('li a', this.$ul).on('mousedown', function(e) {
if (e.shiftKey) {
// Prevent selecting text by Shift+click
return false;
}
});

$('li a', this.$ul).on('touchstart click', function(event) {
event.stopPropagation();

var $target = $(event.target);

if (document.getSelection().type === 'Range') {
var $input = $(this).find("input:first");

$input.prop("checked", !$input.prop("checked"))
.trigger("change");
}


if (event.shiftKey) {
if($target.is("label")){ // Handles checkbox selection manually (see https://github.com/davidstutz/bootstrap-multiselect/issues/431)
event.preventDefault();
$target = $(this).find("input");
$target.prop("checked", !$target.prop("checked")).trigger("change");
}
var checked = $target.prop('checked') || false;

if (checked) {
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/bootstrap-multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ describe('Bootstrap Multiselect Specific Issues', function() {
selection.addRange(range);

if (document.getSelection().type === 'Range') {
$('#multiselect-container').find('a:first').trigger('click');
$('#multiselect-container').find('a:first label').trigger('click');
expect($('#multiselect-container').find('input:first').prop('checked')).toBe(true);
}

Expand Down