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("");
});
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("");
});
Share
Improve this question
edited Jan 5, 2015 at 14:10
Alex
23.3k4 gold badges42 silver badges75 bronze badges
asked Jan 5, 2015 at 14:06
Rafael RoqueRafael Roque
3772 gold badges5 silver badges14 bronze badges
2
- Seems to be working fine on my machine. Using jQ 2.0 and IE11 and Chrome 39. Please post your input element and other event that are attached to it. – Mouser Commented Jan 5, 2015 at 14:26
- $("#field").on("blur", function() { $(this).val(""); }); ? – sodawillow Commented Jan 5, 2015 at 16:52
3 Answers
Reset to default 7try with this, example here in fiddle
$('.typeahead').typeahead().bind('typeahead:close', function () {
$('.typeahead').typeahead('val', '');
});
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', '');
});
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', '')
});