Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 651
Envy Avatar asked Oct 07 '15 12:10

Envy


2 Answers

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

like image 144
the_mishra Avatar answered Sep 28 '22 03:09

the_mishra


You can use ng-keypress="fn($select.search)" at <ui-select...>
And use this function at controller to get the input.

$scope.fn = function(search) {
//do something with search
}
like image 43
AbdelRahman Badr Avatar answered Sep 28 '22 03:09

AbdelRahman Badr