Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap dropdown disappears on input select

I have a Bootstrap dropdown menu I plan to use to login. It appears fine but when I select the username nput it vanishes since the focus has gone to the input. How would I go about adding in support for the inputs or is there a working method for this?

My current code is:

    <li id="fat-menu" class="dropdown">
         <a href="#" id="drop3" role="button" class="dropdown-toggle" data-toggle="dropdown" data-target="#">Login <b class="caret"></b></a>
         <ul class="dropdown-menu" role="menu" aria-labelledby="drop3">
            <li role="presentation"><input name="username" type="text" placeholder="Username" /></li>
            <li role="presentation"><input name="password" type="password" placeholder="Password" /></li>
            <li role="presentation" class="divider"></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Login</a></li>
          </ul>
     </li>

My attempt at jsfiddle. I couldnt get the dropdown to work at all: http://jsfiddle.net/KF8dv/

like image 995
keji Avatar asked Apr 17 '13 03:04

keji


1 Answers

Please see this :- http://jsfiddle.net/b8769/

You need to prevent dropdown event when clicked on input text boxes. You can achhive this by using javascript. stopPropagation

$('.dropdown-menu input').click(function(e) {
        e.stopPropagation(); //This will prevent the event from bubbling up and close the dropdown when you type/click on text boxes.
    });
like image 89
PSL Avatar answered Oct 01 '22 10:10

PSL