Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap input field in dropdown with AngularJS

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>
like image 729
dulan Avatar asked Oct 19 '14 12:10

dulan


2 Answers

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()">
like image 76
dulan Avatar answered Nov 02 '22 21:11

dulan


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>
like image 2
Srinivas Paila Avatar answered Nov 02 '22 23:11

Srinivas Paila