Skip to content

Instantly share code, notes, and snippets.

@kedramon
Created June 16, 2015 09:32
Show Gist options
  • Select an option

  • Save kedramon/5909cac6d2f37d086952 to your computer and use it in GitHub Desktop.

Select an option

Save kedramon/5909cac6d2f37d086952 to your computer and use it in GitHub Desktop.
Handler for the "onkeydown" event to submit the autocomplete input by hitting the Enter key, also input must have a 'auto-submit' class
(function ($) {
Drupal.jsAC.prototype.onkeydown = function (input, e) {
if (!e) {
e = window.event;
}
switch (e.keyCode) {
case 13: // Enter.
if ($(input).hasClass('auto-submit')) {
this.hidePopup(e.keyCode);
input.form.submit();
}
return true;
case 40: // down arrow.
this.selectDown();
return false;
case 38: // up arrow.
this.selectUp();
return false;
default: // All other keys.
return true;
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment