Editable ComboBox using bootstrap/angularjs

后端 未结 4 1853
长情又很酷
长情又很酷 2021-02-04 04:14

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

相关标签:
4条回答
  • 2021-02-04 04:55

    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="http://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!

    0 讨论(0)
  • 2021-02-04 05:08

    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="#" ng-click="changeColor(color)">{{color.name}}</a></li>
                            </ul>
                        </div>
                    </div>
            </div>
        </div>
    </div>
    

    Greetings from Ireland!

    0 讨论(0)
  • 2021-02-04 05:09

    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.

    0 讨论(0)
  • 2021-02-04 05:14

    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

    0 讨论(0)
提交回复
热议问题