Angular-UI: Force Typeahead Team Results

I have a text box that uses the AngularUI typeahead function . It looks like this:

<input typeahead="eye for eye in autocomplete[column] | filter:$viewValue"> 

I would like to get the user to select an option from the generated list. If they type in something that is not indicated in the list exactly as it appears when blurring (clicking outside the text field), I would like the value of the text field to be reset to its original value.

Is this functional part part of the typeahead directive, or do I need to extend it? I searched for about 10 minutes on google and stackoverflow, but could not find the relevant documentation.

Can someone point me in the right direction to accomplish this?

+7
angularjs twitter-bootstrap angular-ui angular-ui-bootstrap angular-ui-typeahead
source share
1 answer

The plugin has an attribute to force the use of only existing values: typeahead-editable="false" . The default value is true .

Only $modelValue set to empty when the wrong value is selected, and it is really necessary, otherwise we could not write anything. $viewValue stays with the last text entered. Perhaps you can associate a blur event with a field with reset $viewValue ?

Here is your JsFiddle with the displayed value: http://jsfiddle.net/ZjPWe/61/

You can also use the typeahead-on-select attribute, which requires a callback when choosing a value, but I'm not sure that it will work with typeahead-editable="false" because the value will not be selected.

+12
source share

All Articles