Skip to content

Commit

Permalink
Merge pull request #1187 from Patternslib/scrum-1670--inject-submit-c…
Browse files Browse the repository at this point in the history
…hild-element

Scrum 1670  inject submit child element
  • Loading branch information
thet authored Nov 4, 2023
2 parents fdf0998 + 3821ca8 commit 7cfd08a
Show file tree
Hide file tree
Showing 3 changed files with 367 additions and 339 deletions.
5 changes: 3 additions & 2 deletions src/pat/ajax/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright 2012-2013 Florian Friesdorf
* Copyright 2012-2013 Marko Durkovic
*/
import "../../core/polyfills"; // SubmitEvent.submitter for Safari < 15.4 and jsDOM
import $ from "jquery";
import logging from "../../core/logging";
import Parser from "../../core/parser";
Expand Down Expand Up @@ -53,8 +54,8 @@ const _ = {
$el.off(".pat-ajax");
},
onClickSubmit(event) {
const el = event.target;
const form = el.closest("form");
const el = event.submitter || event.target;
const form = el.form;
const data = {};
if (el.name) {
data[el.name] = el.value;
Expand Down
13 changes: 3 additions & 10 deletions src/pat/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,18 @@ const inject = {
if ($el[0]?.tagName === "FORM") {
events.add_event_listener(
$el[0],
"click",
"pat-inject--form-submit-click",
"submit",
"pat-inject--form-submit",
(e) => {
if (
e.target.matches(
e.submitter?.matches(
"[type=submit], button:not([type=button]), [type=image]"
)
) {
// make sure the submitting button is sent
// with the form
ajax.onClickSubmit(e);
}
}
);
events.add_event_listener(
$el[0],
"submit",
"pat-inject--form-submit",
(e) => {
this.onTrigger(e);
}
);
Expand Down
Loading

0 comments on commit 7cfd08a

Please sign in to comment.