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.

QuickSubmit.js 792B

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