1

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.

Community
  • 1
  • 1
Nelu
  • 16,644
  • 10
  • 80
  • 88

1 Answers1

2

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

Coyolero
  • 2,353
  • 4
  • 25
  • 34