I’m using bootstrap multiselect (https://github.com/davidstutz/bootstrap-multiselect – current version) in a form. On desktop it’s working fine, but on mobile or if I use the Responsive Design Mode in Firefox or the Toggle Device Emulation in Chrome dev tool, I’m getting an error:
Unable to preventDefault inside passive event listener invocation.
and the select behavior is not working as expected on mobile. I have this error with the default, but also with my custom config:
// Multiselect Config
const opts_template = {
button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span><i class="fa fa-caret-down" aria-hidden="true"></i></button>',
filter: '<div class="multiselect-filter"><div class="input-group"><span class="input-group-btn"><button class="btn btn-default btn-multisearch" type="button" disabled><i class="fa fa-sm fa-search"></i></button></span><input type="search" class="multiselect-search form-control" /><span class="input-group-btn"><button class="btn btn-default multiselect-clear-filter" type="button"><i class="fa fa-sm fa-times"></i></button></span></div></div>',
};
// Multiselect Select One Mininum
function multiSelectOneMin(val) {
if(val.multiselect){
var $element = val.multiselect.$select;
} else {
var $element = $(val.element);
}
let $click = val.click ? val.click : '';
if($element.val().length == 0) {
$element.multiselect('select', $click);
}
}
const opts_basic_one_min = {
nonSelectedText: 'Select',
maxHeight: 250,
buttonWidth: '100%',
templates: opts_template,
onChange: function(element, checked) {
multiSelectOneMin({ multiselect: this, element: null, values: this.$select.val(), click: element.val() });
}
};
$('#subjectContact').multiselect(opts_basic_one_min);
Here is the live form: https://www.qumundo.com/contact/
How can I fix this error on mobile?
I’ve tried deactivating the event.preventDefault() as suggested in some posts:
//event.preventDefault();
but then all the mobile attempts seem to work but not the desktop attempts.
I’ve also noticed that with deactvitating //event.preventDefault(); the multiselect .onChange() is running:
Desktop: 2 times; Mobile: 3 times
If I activate it:
Desktop: 1 time; Mobile: 2 times (including the error)
I’ve also noticed a difference in the Copy Selector and Copy Styles of an option select:
Desktop:
#form-group-subject > span > div > div.multiselect-container.dropdown-menu > button.multiselect-option.dropdown-item.active > span > label
document.querySelector("#form-group-subject > span > div > div.multiselect-container.dropdown-menu > button.multiselect-option.dropdown-item.active > span > label")
Mobile:
#form-group-subject > span > div > div > button.multiselect-option.dropdown-item.active > span > label
document.querySelector("#form-group-subject > span > div > div > button.multiselect-option.dropdown-item.active > span > label")
I’ve also tried:
//$('#subjectContact').multiselect(opts_basic_one_min).change(function(e) { e.preventDefault(); });
I’ve also tried
document.addEventListener('touchstart', function(event) {
event.preventDefault();
console.log('touchstart event');
}, { passive: false } );
Desktop seems to work, but on mobile I can’t open the bootstrap multiselect anymore.
jQuery v3.7.1