mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
1.1 KiB
25 lines
1.1 KiB
import {querySingleVisibleElem} from '../../utils/dom.ts';
|
|
|
|
export function handleGlobalEnterQuickSubmit(target) {
|
|
let form = target.closest('form');
|
|
if (form) {
|
|
if (!form.checkValidity()) {
|
|
form.reportValidity();
|
|
} else {
|
|
// here use the event to trigger the submit event (instead of calling `submit()` method directly)
|
|
// otherwise the `areYouSure` handler won't be executed, then there will be an annoying "confirm to leave" dialog
|
|
form.dispatchEvent(new SubmitEvent('submit', {bubbles: true, cancelable: true}));
|
|
}
|
|
return true;
|
|
}
|
|
form = target.closest('.ui.form');
|
|
if (form) {
|
|
// A form should only have at most one "primary" button to do quick-submit.
|
|
// Here we don't use a special class to mark the primary button,
|
|
// because there could be a lot of forms with a primary button, the quick submit should work out-of-box,
|
|
// but not keeps asking developers to add that special class again and again (it could be forgotten easily)
|
|
querySingleVisibleElem<HTMLButtonElement>(form, '.ui.primary.button')?.click();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|