When using Bootstrap 4.1, you may encounter issues with checkboxes in a dropdown menu becoming unclickable after clicking an item. If anyone has found a better solution, please share.
<ul class="dropdown-menu dropdown-menu-form">
<li><label class="checkbox"><input type="checkbox">One</label></li>
<li><label class="checkbox"><input type="checkbox">Two</label></li>
</ul>
Add the following JS code:
// Enable forms/checkboxes in Bootstrap dropdown menus without causing them to disappear.
$(document).on('click', '.dropdown-menu.dropdown-menu-form', function(e) {
e.stopPropagation();
});
UPDATE
The code works well, but checkbox events trigger twice. Using the onchange
event instead of onclick
resolves this issue:
<ul class="dropdown-menu dropdown-menu-form">
<li><label class="checkbox"><input type="checkbox" onchange="some()">One</label></li>
<li><label class="checkbox"><input type="checkbox" onchange="some()">Two</label></li>
</ul>
Include the following jQuery code:
$(document).on('click', '.dropdown-menu', function (e) {
e.stopPropagation();
});