1export function handleGlobalEnterQuickSubmit(target) {
2 const form = target.closest('form');
3 if (form) {
4 if (!form.checkValidity()) {
5 form.reportValidity();
6 return;
7 }
8
9 // here use the event to trigger the submit event (instead of calling `submit()` method directly)
10 // otherwise the `areYouSure` handler won't be executed, then there will be an annoying "confirm to leave" dialog
11 form.dispatchEvent(new SubmitEvent('submit', {bubbles: true, cancelable: true}));
12 } else {
13 // if no form, then the editor is for an AJAX request, dispatch an event to the target, let the target's event handler to do the AJAX request.
14 // the 'ce-' prefix means this is a CustomEvent
15 target.dispatchEvent(new CustomEvent('ce-quick-submit', {bubbles: true}));
16 }
17}