How to get value which typed in ui-select search box?

Envy picture Envy · Oct 7, 2015 · Viewed 8k times · Source

I'm using ui-select (https://github.com/angular-ui/ui-select).

ui-select support us to Search, Select, and Multi-select. But how can I get the value users typed in ui-select search box? I want to display an error message if the value users typed is not correct.

Example: In this plunker below with Select2 theme, when the user type: 'asdasd' (this text does not match with any results) I want display a message "Do not find any results!" by assigning to 'scope.person.selected'

plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview

How can I do that?

Thanks so much!

Answer

the_mishra picture the_mishra · Apr 19, 2017

The input data in angular_ui_select goes into the $select.search model. You could use refresh attribute of ui-select-choice. Just pass the function in refresh="test($select.search)",and set delay and min input length using refresh-delay and minimum-input-length attributes respectively. here is an quick example:

<ui-select ng-model="model" theme="theme">
     <ui-select-match>{{data}}</ui-select-match>
     <ui-select-choices repeat="options in data" refresh="yourFunction($select.search)" refresh-delay="100" minimum-input-length="1"></ui-select-choices>      
</ui-select>

I would suggest you go through the documentation, hope it would help. angular-ui-select