1

I am looking for dropdown with textbox in angularJS. Currently I am using tag. I have filter condition also. Not sure how to save the user typed value.

      <span>
            <ui-select
            ng-model="ele.test"
            theme="selectize"
            class="form-select-control select-dropdown-fixed-position"
            style="width:16em;text-align:left"
            name="test"
            ng-change="someEvent(ele)"
            ng-model-options="{ updateOn : 'default blur' }">
                <ui-select-match
                    placeholder="Test">{{$select.selected}}</ui-select-match>
                    <ui-select-choices
                            repeat="test in testList| filter: $select.search">
                        <span ng-bind-html="test | highlight: $select.search"></span>
                    </ui-select-choices>
            </ui-select>
        </span>

If user enters any value other than the values listed in dropdown I have to save it. I have tried with tag but it didn't work.

Any help is appreciated.

swathi
  • 31
  • 5

2 Answers2

0

You can save it by using the value of $scope.ele.test which holds the value of the entered text.

var myVal = $scope.ele.test;

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Hi, thanks for the reply. ele.test value is having empty value. After typing something in dropdown and click outside the value is disappearing. I tried reset-search-input but didn't work. – swathi Nov 04 '18 at 19:37
0

I was looking for allow user to input in the dropdown, if user entered value is not in the list then save it. I found the below solution here.Allow manually entered text in ui-select

   <ui-select ng-model="superhero.selected">
   <ui-select-match placeholder="Select or search a superhero ..."> 
       {{$select.selected}}</ui-select-match>
   <ui-select-choices repeat="hero in getSuperheroes($select.search) 
         |filter: $select.search">
       <div ng-bind="hero"></div>
   </ui-select-choices>
   </ui-select>

In controller

   $scope.getSuperheroes = function(search) {
    var newSupes = $scope.superheroes.slice();
    if (search && newSupes.indexOf(search) === -1) {
    newSupes.unshift(search);
   }
   return newSupes;
   }
swathi
  • 31
  • 5