Editable ComboBox using bootstrap/angularjs

All we need is an easy explanation of the problem, so here it is.

I am not getting any solution for having combobox as select as well as input. That means if user selection in not there in per-populated list , then use should be able to enter his value of choice.
users choice (selected or entered) should be set and retrievable as ng-model in angularjs.

thanks

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

ui-select doesn’t really look like a proper select we are all used to.
So here is what i ended up doing with the help Twitter Bootstrap 3:

http://jsfiddle.net/ruslans_uralovs/2brhd/1/

<div ng-app >
    <div class="row" ng-controller="ExampleController">
        <div class="col-xs-8 col-xs-offset-2">

            <form role="form">
                <div class="input-group">
                    <input type="text" class="form-control" ng-model="myColor.name">
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
                        <ul id="color-dropdown-menu" class="dropdown-menu dropdown-menu-right" role="menu">
                            <li ng-repeat="color in colors" class="input-lg"><a href="#" rel="nofollow noreferrer noopener" ng-click="changeColor(color)">{{color.name}}</a></li>
                        </ul>
                    </div>
                </div>
        </div>
    </div>
</div>

Greetings from Ireland!

Method 2

The ui-select2 library lets you use select2 through a directive. That provides some great UI elements that do what you’re asking for.

In general I also recommend the Angular Modules site to find various useful Angular libraries.

Method 3

Using html5 you can do this:

    <input type=text list=browsers >
    <datalist id=browsers >
       <option> Google
       <option> IE9
    </datalist>

Got it from here:
http://www.scriptol.com/html5/combobox.php

Method 4

I also was looking for the same thing and didn’t find a good solution, so I ended up creating angular-combo-box directive which lets you do what you are looking for. Here’s an example.

angular.module('ngComboBoxExample', ['ngComboBox'])
  .controller('myController', function($scope) {
    $scope.options = [
      'Blue',
      'Red',
      'Pink',
      'Purple',
      'Green'
    ];
    $scope.color = '';
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://bradleytrager.github.io/angular-combo-box/bower_components/angular-combo-box/dist/angular-combo-box.min.js"></script>

<div ng-app="ngComboBoxExample">
  <div ng-controller="myController">
    <combo-box options="options" combo-model="color" label="--Select a Color--" other-label="A color not on the list...">
    </combo-box>
    <div>Selected Color: <span ng-bind="color"></span>
    </div>
  </div>
</div>

Hope it helps!

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply