Skip to content

Commit

Permalink
Issue #12071: Don't submit forms when typing Tab on an input.
Browse files Browse the repository at this point in the history
  • Loading branch information
simartin committed Jul 12, 2016
1 parent 8cb05a3 commit ff4e07b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
17 changes: 13 additions & 4 deletions components/script/dom/htmlinputelement.rs
Expand Up @@ -33,6 +33,7 @@ use dom::validation::Validatable;
use dom::virtualmethods::VirtualMethods;
use ipc_channel::ipc::{self, IpcSender};
use mime_guess;
use msg::constellation_msg::Key;
use net_traits::IpcSend;
use net_traits::filemanager_thread::{FileManagerThreadMsg, FilterPattern};
use script_traits::ScriptMsg as ConstellationMsg;
Expand Down Expand Up @@ -1046,10 +1047,18 @@ impl VirtualMethods for HTMLInputElement {
let action = self.textinput.borrow_mut().handle_keydown(keyevent);
match action {
TriggerDefaultAction => {
self.implicit_submission(keyevent.CtrlKey(),
keyevent.ShiftKey(),
keyevent.AltKey(),
keyevent.MetaKey());
if let Some(key) = keyevent.get_key() {
match key {
Key::Enter | Key::KpEnter =>
self.implicit_submission(keyevent.CtrlKey(),
keyevent.ShiftKey(),
keyevent.AltKey(),
keyevent.MetaKey()),
// Issue #12071: Tab should not submit forms
// TODO(3982): Implement form keyboard navigation
_ => (),
}
};
},
DispatchInput => {
self.value_changed.set(true);
Expand Down
6 changes: 6 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -6480,6 +6480,12 @@
"url": "/_mozilla/mozilla/form_submit_about.html"
}
],
"mozilla/form_tab_keyevent.html": [
{
"path": "mozilla/form_tab_keyevent.html",
"url": "/_mozilla/mozilla/form_tab_keyevent.html"
}
],
"mozilla/getBoundingClientRect.html": [
{
"path": "mozilla/getBoundingClientRect.html",
Expand Down
27 changes: 27 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/form_tab_keyevent.html
@@ -0,0 +1,27 @@
<!doctype html>
<meta charset="utf-8">
<html>
<body>
<title>Test for issue #12071</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<form name="f" id="f">
<input type="text" name="input1" id="input1"/>
<input type="submit" value="Submit"/>
</form>
<script>
var test = async_test("TabShouldNotSubmit");
var form = document.getElementById('f');
var form_submitted = false;
form.onsubmit = function(e) { form_submitted = true; return false; };
document.addEventListener("DOMContentLoaded", function() {
test.step(function() {
var input = document.getElementById('input1');
var evt = new KeyboardEvent("keydown", {key : "Tab"});
input.dispatchEvent(evt);
});
});
test.step_timeout(function() { assert_false(form_submitted, "Form should not be submitted"); test.done(); }, 500);
</script>
</body>
</html>

0 comments on commit ff4e07b

Please sign in to comment.