Skip to content

Instantly share code, notes, and snippets.

@atzkey
Created September 10, 2010 21:24
Show Gist options
  • Save atzkey/574398 to your computer and use it in GitHub Desktop.
Save atzkey/574398 to your computer and use it in GitHub Desktop.
/*
jQuery UI Autocomplete AutoFill extension
automatically fills in the input box when only one suggestion is to be shown
*/
;(function($) {
$.extend($.ui.autocomplete.options, {autoFill: true});
$.extend($.ui.autocomplete.prototype, {
_response_original: $.ui.autocomplete.prototype._response,
_response: function(content) {
if (this.options.autoFill && content.length == 1) {
content = this._normalize(content);
this.element.val(content[0].value);
this.close();
this.element.removeClass("ui-autocomplete-loading");
return;
}
this._response_original(content);
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment