2

I'm using https://github.com/angular-ui/ui-select and I want to do some event or an option that will allow me to call an event (opening a modal) when no result is found while using a filter.

<ui-select ng-model="SelectedCustomer.selected" theme="select2">
<ui-select-match placeholder="Enter Customer">
    {{$select.selected.NAME}}
</ui-select-match>
<ui-select-choices repeat="customer in Customers | filter: $select.search">
    <div ng-bind-html="customer.NAME | highlight: $select.search"></div>            
</ui-select-choices>

AbdelRahman Badr
  • 193
  • 3
  • 15

3 Answers3

4

You can add the <ui-select-no-choice> directive inside the ui-select directive after the ui-choices like below:

<ui-select multiple ng-model="something" >
  <ui-select-match placeholder="something" allow-clear="true">
  </ui-select-match>
  <ui-select-choices>
  </ui-select-choices>
  <ui-select-no-choice>
      This is where your code goes in. You can display some message or you can create a button too.
  </ui-select-no-choice>
</ui-select>

This will work like you wish. For reference and usage you can see ui-select-no-choice documentation

Ragul Parani
  • 621
  • 7
  • 22
  • This is a useful directive to know about, but it does not meet the OP's request for a solution that will "allow me to call an event (opening a modal) when no result is found while using a filter", unless requiring the user to click a button is acceptable. But my impression was that the intent was for the event to be triggered immediately. – Sean the Bean Nov 12 '16 at 22:28
0

Just add a div below your ui-select for your option using ng-if. Like so:

 <ui-select-choices 
    ng-repeat="customer in filterSearch = ( Customers | $select.search)">
    <div ng-bind-html="customer.NAME | highlight: $select.search"></div>            
 </ui-select-choices>
<div ng-if="!filterSearch"><button ng-click="openDialog()"></button></div>

What is $search in your example?

brewsky
  • 607
  • 1
  • 9
  • 15
  • $search, is the input text I'm searching with provided by ui-select plug-in. This is valid If I'm making my own custom filter, ui-select is doing it for me. – AbdelRahman Badr Feb 01 '16 at 11:18
0

I found a workaround here https://stackoverflow.com/a/32914532/4335165 by repeating the results coming from a function and handling the event on the on-select.

Community
  • 1
  • 1
AbdelRahman Badr
  • 193
  • 3
  • 15