Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 572 Bytes

javascript-form-submit-notes.md

File metadata and controls

23 lines (18 loc) · 572 Bytes

JavaScript Form Submit Notes

Problem: There is no way to tell in JS if there are events assigned to a DOM element.

Possible solutions:

  • If you are using Stimulus, look at the actions on the form and check if submit actions exist
  • Add a data attribute to form if event handlers exist hasHandlers or something
// This causes a double submit
setTimeout(() => {
  form.dispatchEvent(new CustomEvent("submit"));
}, delay);

setTimeout(() => {
  if (form.dataset.remote) {
    Rails.fire(form, "submit");
  } else {
    form.submit();
  }
}, delay);