7

I have a dropdown menu using Bootstrap and inside it, there is an input field. Everytime I click the input field, the dropdown menu disappears. How would I stop that?

By the way, I'm using AngularJS, so jQuery way probably won't fit in here.

<div class="dropdown">
    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
        <span class="pull-left">{{ trans('text.choose_user') }}</span> 
        <span class="pull-right"><i class="icon-order-table"></i></span>
    </button>
    <ul class="dropdown-menu" role="menu">
        <li role="presentation" class="basic-padding"><a role="menuitem" tabindex="-1" href="#">{{ trans('text.guest') }}</a></li>
        <li class="basic-padding">
            <div class="input-group">
                <input type="search" class="form-control" placeholder="{{ trans('text.search') }}">
                <span class="input-group-btn">
                    <button class="btn btn-default">
                        <i class="icon-search"></i>
                    </button>
                </span>
            </div>
        </li>
    </ul>
</div>
1
  • 2
    Try adding ng-click="$event.preventDefault()" to the input element. Commented Oct 19, 2014 at 13:10

2 Answers 2

12

Thanks to @Rob J, I've come up with a solution, not exactly as what he mentioned though:

<input type="search" class="form-control" placeholder="{{ trans('text.search') }}" ng-click="$event.stopPropagation()">
Sign up to request clarification or add additional context in comments.

2 Comments

mark this as answer - it works and may be helpful for others (like me :) )
Works like a charm with ui-bootstrap as well. Thanks
2

You should try using angular ui-select. Here's link to github

Link to plunker demo

Go through the documentation and there are several options to configure ui-select.

Sample code to configure ui-select

<ui-select ng-model="person.selected" theme="bootstrap" style="min-width: 300px;">
  <ui-select-match placeholder="Select a person...">{{$select.selected.name}}</ui-select-match>
  <ui-select-choices repeat="person in people | propsFilter: {name: $select.search}">
    <div ng-bind-html="person.name | highlight: $select.search"></div>
  </ui-select-choices>
</ui-select>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.