Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to close the dropdown menu for typeahead.js?

I'm using typeahead.js for a typeahead.

I basically want to do the reverse of this: Programmatically triggering typeahead.js result display

I've tried to do a .trigger('blur'); on the typeahead, but I set the value right before that by doing .typeahead('setQuery', value);. Doing 'setQuery' fires off an ajax request to fetch results with the new query term. So the "blur" takes place, but the box is opened soon thereafter.

like image 210
nwalke Avatar asked Aug 14 '13 21:08

nwalke


2 Answers

The proper way to do this, as of version 0.11:

$('.typeahead').typeahead('close');

Manual: https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#jquerytypeaheadclose

like image 196
Razvan Grigore Avatar answered Sep 26 '22 15:09

Razvan Grigore


Ref: https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md

$('.typeahead-input').typeahead('close');

Undocumented but there is way to set precondition and not allow dropdown to open:

$('.typeahead-input').on('typeahead:beforeopen', function() {
    return false;
});
like image 45
Nitin... Avatar answered Sep 26 '22 15:09

Nitin...