Skip to content

Commit

Permalink
Allow <input type=image> to submit forms
Browse files Browse the repository at this point in the history
  • Loading branch information
jenseng committed Jan 7, 2023
1 parent 22f7c3c commit 59a8af3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jsdom/living/nodes/HTMLInputElement-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class HTMLInputElementImpl extends HTMLElementImpl {
fireAnEvent("input", this, undefined, { bubbles: true });
fireAnEvent("change", this, undefined, { bubbles: true });
}
} else if (form && this.type === "submit") {
} else if (form && (this.type === "submit" || this.type === "image")) {
form._doRequestSubmit(this);
} else if (form && this.type === "reset") {
form._doReset();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: form submitters</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
"use strict";

let isSubmitted;
function prepareForm() {
isSubmitted = false;
const form = document.createElement("FORM");
form.addEventListener("submit", event => {
event.preventDefault();
isSubmitted = true;
});
document.body.appendChild(form);
form.innerHTML = `
<button type="submit" />
<button type="button" />
<input type="submit" />
<input type="image" />
<input type="text" />
`;
return form;
}

test(() => {
const form = prepareForm();
form.querySelector("button[type=submit]").click();
assert_true(isSubmitted, "Form is submitted");
}, "Form is submitted by submit buttons");

test(() => {
const form = prepareForm();
form.querySelector("button[type=button]").click();
assert_false(isSubmitted, "Form is not submitted");
}, "Form is not submitted by other button types");

test(() => {
const form = prepareForm();
form.querySelector("input[type=submit]").click();
assert_true(isSubmitted, "Form is submitted");
}, "Form is submitted by submit inputs");

test(() => {
const form = prepareForm();
form.querySelector("input[type=image]").click();
assert_true(isSubmitted, "Form is submitted");
}, "Form is submitted by image inputs");

test(() => {
const form = prepareForm();
form.querySelector("input[type=text]").click();
assert_false(isSubmitted, "Form is not submitted");
}, "Form is not submitted by other input types");
</script>

0 comments on commit 59a8af3

Please sign in to comment.