Skip to content

Commit 22d814f

Browse files
committed
fix(pat-inject): For submit buttons with a formaction, do not call ajax.onClickSubmit twice.
1 parent bb8ce9d commit 22d814f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/pat/inject/inject.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ const inject = {
9797
// setup event handlers
9898
if ($el.is("form")) {
9999
$el.on("submit.pat-inject", this.onTrigger.bind(this))
100-
.on("click.pat-inject", "[type=submit]", ajax.onClickSubmit)
100+
.on(
101+
"click.pat-inject",
102+
"[type=submit]:not([formaction])",
103+
ajax.onClickSubmit
104+
)
101105
.on(
102106
"click.pat-inject",
103107
"[type=submit][formaction], [type=image][formaction]",

src/pat/inject/inject.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,25 @@ describe("pat-inject", function () {
12211221
"other"
12221222
);
12231223
});
1224+
1225+
it("9.2.5.10 - does not call ajax.onClickSubmit twice.", async function () {
1226+
document.body.innerHTML = `
1227+
<form class="pat-inject">
1228+
<button type="submit" formaction="test.cgi"/>
1229+
</form>
1230+
`;
1231+
1232+
const pat_ajax = (await import("../ajax/ajax.js")).default;
1233+
jest.spyOn(pat_ajax, "onClickSubmit");
1234+
1235+
const form = document.querySelector("form");
1236+
const button = form.querySelector("button");
1237+
1238+
pattern.init($(form));
1239+
button.click();
1240+
1241+
expect(pat_ajax.onClickSubmit).toHaveBeenCalledTimes(1);
1242+
});
12241243
});
12251244
});
12261245
});

0 commit comments

Comments
 (0)