From d41d367c35480588fc13470558554e0806cc2cfc Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 18 Feb 2024 14:36:41 +0800 Subject: [PATCH] Make submit event code work with both jQuery event and native event (#29223) (#29234) Backport #29223 (no conflict) --- web_src/js/features/common-issue-list.js | 2 +- web_src/js/features/repo-diff.js | 2 +- web_src/js/utils/dom.js | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/common-issue-list.js b/web_src/js/features/common-issue-list.js index 317c11219..8182f99f2 100644 --- a/web_src/js/features/common-issue-list.js +++ b/web_src/js/features/common-issue-list.js @@ -40,7 +40,7 @@ export function initCommonIssueListQuickGoto() { $form.on('submit', (e) => { // if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly let doQuickGoto = !isElemHidden($goto); - const submitter = submitEventSubmitter(e.originalEvent); + const submitter = submitEventSubmitter(e); if (submitter !== $form[0] && submitter !== $input[0] && submitter !== $goto[0]) doQuickGoto = false; if (!doQuickGoto) return; diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index eeb80e91b..6d6f38261 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -58,7 +58,7 @@ function initRepoDiffConversationForm() { const formData = new FormData($form[0]); // if the form is submitted by a button, append the button's name and value to the form data - const submitter = submitEventSubmitter(e.originalEvent); + const submitter = submitEventSubmitter(e); const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit'); if (isSubmittedByButton && submitter.name) { formData.append(submitter.name, submitter.value); diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index 4dc55a518..fb6b75114 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -211,6 +211,7 @@ export function loadElem(el, src) { const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined'; export function submitEventSubmitter(e) { + e = e.originalEvent ?? e; // if the event is wrapped by jQuery, use "originalEvent", otherwise, use the event itself return needSubmitEventPolyfill ? (e.target._submitter || null) : e.submitter; }