I put a form inside a bootstrap dropdown, but when I click any of the fields in the form, the dropdown goes away. I have this piece of code but I don't know where to put it to prevent the dropdown disappearing.
$(function test() {
// Setup drop down menu
$('.dropdown-toggle').dropdown();
// Fix input element click problem
$('.dropdown input, .dropdown label').click(function(e) {
e.stopPropagation();
});
});
Could someone please tell me where I should put this? I tried in the bootstrap-dropdown, I tried within the HTML but it still doesn't work.
If you want to stop closing only some of dropdown menu, not all of them, then just add an additional class to your ul block:
And use this code:
Time passed since answer had been accepted, but if you want to keep the dropdown opened, if it acts like a kind of dialog, the best way i think is:
Thank you for the above answer, I was having the same issue w/ submenus under the dropdown menus. Using the above solution I was able to solve the problem for this as well.
If you look to the bottom of sources of dropdown widget, you will see this:
So you have the following choices:
This works for my (lateral sidebar opening a simple link with bootstrap toggle)
Put
on the original answer, remove all the classes, and just put the ".dropdown-menu" class, it worked for me. i have an input field inside the dropdown menu.