Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1782 from mozilla/issue_1780_enter_key
Fix submit occuring when selecting an email address in Firefox from the autocomplete list.
  • Loading branch information
lloyd committed Jun 19, 2012
2 parents 0985e0b + 2db0285 commit 44cd4a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions resources/static/shared/modules/page_module.js
Expand Up @@ -15,7 +15,7 @@ BrowserID.Modules.PageModule = (function() {
cancelEvent = helpers.cancelEvent,
mediator = bid.Mediator;

function onKeypress(event) {
function onKeyup(event) {
if (event.which === 13) {
// IE8 does not trigger the submit event when hitting enter. Submit the
// form if the key press was an enter and prevent the default action so
Expand Down Expand Up @@ -69,7 +69,7 @@ BrowserID.Modules.PageModule = (function() {
self.options = options || {};

self.bind("form", "submit", cancelEvent(onSubmit));
self.bind("input", "keypress", onKeypress);
self.bind("input", "keyup", onKeyup);
},

stop: function() {
Expand Down
9 changes: 5 additions & 4 deletions resources/static/test/cases/shared/modules/page_module.js
Expand Up @@ -200,7 +200,7 @@
equal(submitCalled, true, "submit permitted to complete");
});

test("form is submitted once 'enter keypress' event", function() {
test("form is submitted on 'enter keyup' event", function() {
createController();
controller.renderDialog("test_template_with_input", {
title: "Test title",
Expand All @@ -216,14 +216,15 @@
};

// synthesize the entire series of key* events so we replicate the behavior
// of keyboard interaction.
// of keyboard interaction. The order of events is keydown, keypress,
// keyup (http://unixpapa.com/js/key.html).
var e = jQuery.Event("keydown", { keyCode: 13, which: 13 });
$("#templateInput").trigger(e);

var e = jQuery.Event("keyup", { keyCode: 13, which: 13 });
var e = jQuery.Event("keypress", { keyCode: 13, which: 13 });
$("#templateInput").trigger(e);

var e = jQuery.Event("keypress", { keyCode: 13, which: 13 });
var e = jQuery.Event("keyup", { keyCode: 13, which: 13 });
$("#templateInput").trigger(e);

equal(submitCalled, 1, "submit called a single time");
Expand Down

0 comments on commit 44cd4a2

Please sign in to comment.