Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear typeahead field

how could I clear a typeahead field in a focusout event?

The following jQuery code doesn´t seem to work in a typeahead field:

$( "#field" ).focusout(function() {
    $(this).val("");
});
like image 532
Rafael Roque Avatar asked Jan 05 '15 14:01

Rafael Roque


People also ask

How do you clear the Typeahead input after a result is selected?

preventDefault() will make sure that the model is not updated and the input field is not updated with the selected item. But text entered by a user will still be part of the input so if you want to clear up this as well you can directly update the input 's value property. Save this answer.

What should I use the Typeahead for?

Typeahead is commonly used to improve the experience of users. This tool looks at the text entered by the user while they search for something or fill a form. On the basis of these things, Typeahead provides hints and lists of possible choices to the users. The search can be of any type.

What is Typeahead control?

The typeahead input fields are very popular in modern web forms. The main purpose of using typeahead is to improve the user experience by supplying hints or a list of possible choices based on the text they've entered while filling a form or searching something — like the Google instant search.

What is Typeahead jQuery?

by Tom Bertrand. jQuery plugin that provides Typeahead (autocomplete) Search preview from Json object(s) via same domain Ajax request or cross domain Jsonp and offers data compression inside Local Storage. The plugin is built with a lot of options and callbacks to allow customization.


1 Answers

try with this, example here in fiddle

$('.typeahead').typeahead().bind('typeahead:close', function () {
    $('.typeahead').typeahead('val', '');
});
like image 178
Diego Rodriguez Avatar answered Nov 12 '22 20:11

Diego Rodriguez