Reputation: 377
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("");
});
Upvotes: 7
Views: 16336
Reputation: 120
try with this, example here in fiddle
$('.typeahead').typeahead().bind('typeahead:close', function () {
$('.typeahead').typeahead('val', '');
});
Upvotes: 7
Reputation: 515
Thanks for all the answers, but the close event did not work for me maybe my setting or something has deprecated. so I have written this code and it worked well.
$('#typeahead-id').typeahead().bind('typeahead:selected', function() {
$('#typeahead-id').typeahead('val', '')
});
Upvotes: 2
Reputation: 4093
The accepted answer is now out of date. See the latest Typeahead documentation to see that trapping the "close" event and setting the value of the input are different. Here's an equivalent, updated answer:
$('.typeahead').typeahead().bind('typeahead:close', function() {
$('.typeahead').typeahead('val', '');
});
Upvotes: 3