Skip to content

Instantly share code, notes, and snippets.

@BenConstable
Created January 15, 2013 22:30
Show Gist options
  • Save BenConstable/4542776 to your computer and use it in GitHub Desktop.
Save BenConstable/4542776 to your computer and use it in GitHub Desktop.
Make the jQuery UI Autocomplete widget appear on blur, not keypress.
/*
* Use the small setup below to make the
* jQuery Autocomplete widget show on input-blur,
* rather than on every keypress.
*/
(function ($) {
var field = $('.selector');
field.autocomplete({
select: function (e, ui) {
// Make sure the input has its value set properly
field.val(ui.item.value);
},
change: function (e, ui) {
// This prevents the autocomplete from showing straight after selecting a response
if (typeof(ui.item) === 'undefined' || ui.item.value !== field.val()) {
field.autocomplete('search');
}
}
}).unbind('keypress keydown input focus'); // Remove unwanted events
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment