Typeahead.js: Add a Clear Method

Created on 23 Mar 2013  路  8Comments  路  Source: twitter/typeahead.js

Any chance we could get a clear method to clear the input and typeahead's results? Using jQuery's .val(''); on the input element clears it, but when you focus typeahead adds the last entered text back in. Having a clear method would be useful to create a clear button (similar to the iOS standard search fields) for small screen touch devices where selecting and clearing inputs is a bit more tedious.

Most helpful comment

$('.typeahead').typeahead('val', myVal); worked for me

All 8 comments

:+1:

Adding something like this has been discussed in #28 鈥撀爄t's definitely something that'll get added at some point.

Awesome, look forward to it and thanks for all the hard work. This is def the best autocomplete/suggestion type plugin I've used yet.

v0.9.1, which should go out shortly, has a jQuery#typeahead('setQuery', query) plugin method that will allow you to implement a clear method:

$('.typeahead').typeahead('setQuery', '');

Nice, thanks again for this one

how about a clear icon ?

$('.typeahead').typeahead('val', myVal); worked for me

This could help, I resolved this simulating the click on cancel button

$('.typeahead__cancel-button').trigger('mousedown');

Was this page helpful?
0 / 5 - 0 ratings