-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix loading button with invalid form #20754
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,16 +142,12 @@ export function initGlobalCommon() { | |
} | ||
}); | ||
|
||
// loading-button this logic used to prevent push one form more than one time | ||
$(document).on('click', '.button.loading-button', function (e) { | ||
const $btn = $(this); | ||
|
||
if ($btn.hasClass('loading')) { | ||
e.preventDefault(); | ||
return false; | ||
} | ||
|
||
$btn.addClass('loading disabled'); | ||
// prevent multiple form submissions on forms containing .loading-button | ||
document.addEventListener('submit', (e) => { | ||
const btn = e.target.querySelector('.loading-button'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the slight feeling that @wxiaoguang won't like this change as it mixes native DOM APIs with jQuery again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but I'm not going to write jQuery just because it "fits" better. jQuery can go to hell if you ask me 😉. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with it since it's a full function without other dependency. I just have objection to something like |
||
if (!btn) return; | ||
if (btn.classList.contains('loading')) return e.preventDefault(); | ||
btn.classList.add('loading'); | ||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this break
<a>
s with thebutton
style class?Links can't be submitted, right?
But is there even a link that satisfies alll these requirements?
I haven't found any with the
loading-button
class, but simplebutton
links are common...(Of course, that was only a small search I did...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
<a>
can not submit a form in HTML, only through JS would that be possible. Searching forloading-button
intemplates
yields exactly 3 buttons that use this class, so I think we should keep the selector simple and independent of the Fomantic-specific.button
class.