Created
January 15, 2013 22:30
-
-
Save BenConstable/4542776 to your computer and use it in GitHub Desktop.
Make the jQuery UI Autocomplete widget appear on blur, not keypress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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