Nelu
Nelu

Reputation: 18700

Close Twitter typeahead on Enter key in AngularJS

I have a search field using Twitter typeahead with this Angular directive.

I can't figure out how to close the typeahead suggestions when I hit Enter (i.e. when none of the suggestions are picked). Can anyone help me out please?

I can fire search through a separate directive when Enter is pressed, but I don't know how to close the suggestions.

I could use this hack when I run search:

jQuery('.tt-dropdown-menu').hide();
jQuery('.tt-hint').hide();

and jQuery('.tt-hint').show(); on other key presses, but there must be a more proper way.

Upvotes: 1

Views: 566

Answers (1)

Coyolero
Coyolero

Reputation: 2433

You could put the typeahead inside a form and adding a display: none submit button

 <form novalidate>
      <input type="text"             
             ng-model="myModel"
             typeahead="something.value for something in myList" />
      <input type="submit" value="Submit" style="display: none">
</form>

That would close the typeahead directive when you hit enter

Upvotes: 2

Related Questions