Skip to content

Instantly share code, notes, and snippets.

@cafuego
Created March 5, 2014 23:28
Show Gist options
  • Save cafuego/9378959 to your computer and use it in GitHub Desktop.
Save cafuego/9378959 to your computer and use it in GitHub Desktop.
(function($) {
/**
* Keep an unmodified copy of the core search callback function.
*/
Drupal.ACDB.prototype.coreSearch = Drupal.ACDB.prototype.search;
/**
* Override the search callback.
*
* Prevent autocomplete search from running if the search string is shorter
* than the limit. Otherwise, call the clone of the original search callback.
*/
Drupal.ACDB.prototype.search = function (searchString) {
var limit = Drupal.settings.autocomplete_limit['limit'];
// Do not search if the string is too short.
if (limit && searchString.length < limit) {
return;
}
// Call the original core search callback.
return this.coreSearch(searchString);
};
// Good night, and good luck.
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment