My UI has some dropdowns created from Bootstrap, which I am using to contain some form elements. I am preventing the dropdown from closing with the solution I found here, which is almost perfect: Avoid dropdown menu close on click inside
The remaining issue is the specific instance where I use a Select2 mutliple select and remove an option. The act of removing appears to follow a different event chain as it closes the dropdown. My assumption is that the event is propagating up to a parent element, but I am seemingly unable to determine which.
Here is a JSFiddle to illustrate the issue. Select an option, and then remove it to see what happens. Below is the code as required when including a jsfiddle. It's pared down from my actual code, of course, but represents the issue at least.
$('body').on('click', '.dropdown .cycle-element', function(e) {
$(this).parent().toggleClass('open');
});
$('body').on('click', function(e) {
if (!$('.dropdown').is(e.target) && $('.dropdown').has(e.target).length === 0 && $('.open').has(e.target).length === 0) {
$('.dropdown').removeClass('open');
}
});
$('.dependency-select').select2();
click me
close the dropdown? and Keep select options open on user selection? – Callean