mirror of
https://github.com/go-gitea/gitea
synced 2024-11-07 09:15:53 +01:00
Make submit event code work with both jQuery event and native event (#29223)
Partially related to #29200 and fix other potential bugs. Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
5e1bf3efe2
commit
658cbddbfb
@ -40,7 +40,7 @@ export function initCommonIssueListQuickGoto() {
|
|||||||
$form.on('submit', (e) => {
|
$form.on('submit', (e) => {
|
||||||
// if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly
|
// if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly
|
||||||
let doQuickGoto = !isElemHidden($goto);
|
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 (submitter !== $form[0] && submitter !== $input[0] && submitter !== $goto[0]) doQuickGoto = false;
|
||||||
if (!doQuickGoto) return;
|
if (!doQuickGoto) return;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ function initRepoDiffConversationForm() {
|
|||||||
const formData = new FormData($form[0]);
|
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
|
// 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');
|
const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit');
|
||||||
if (isSubmittedByButton && submitter.name) {
|
if (isSubmittedByButton && submitter.name) {
|
||||||
formData.append(submitter.name, submitter.value);
|
formData.append(submitter.name, submitter.value);
|
||||||
|
@ -211,6 +211,7 @@ export function loadElem(el, src) {
|
|||||||
const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined';
|
const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined';
|
||||||
|
|
||||||
export function submitEventSubmitter(e) {
|
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;
|
return needSubmitEventPolyfill ? (e.target._submitter || null) : e.submitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user