Sha256: 9f08b1b13a2392ffbe4450030edd744f91696b34fc36c803f368a00e22c0c694

Contents?: true

Size: 1.22 KB

Versions: 34

Compression:

Stored size: 1.22 KB

Contents

import Rails from "@rails/ujs";

// Make the remote form submit buttons disabled when the form is being
// submitted to avoid multiple submits.
document.addEventListener("ajax:beforeSend", (ev) => {
  if (!ev.target.matches("form[data-remote]")) {
    return;
  }

  ev.target.querySelectorAll("[type=submit]").forEach((submit) => {
    submit.disabled = true;
  });
});
document.addEventListener("ajax:complete", (ev) => {
  if (!ev.target.matches("form[data-remote]")) {
    return;
  }

  ev.target.querySelectorAll("[type=submit]").forEach((submit) => {
    submit.disabled = false;
  });
});

// The forms that are attached to Foundation Abide do not work properly with
// Rails UJS Ajax forms that have the `data-remote` attribute attached to
// them. The reason is that in case Foundation Abide sees the form as valid,
// it will submit it normally bypassing the Rails UJS functionality.
// The submit events happens through jQuery in Foundation Abide which is why
// we need to bind the event with jQuery.
$(document).on("submit", "form[data-remote][data-abide]", (ev) => {
  ev.preventDefault();

  if (ev.target.querySelectorAll("[data-invalid]").length > 0) {
    return;
  }

  Reflect.apply(Rails.handleRemote, ev.target, [ev]);
});

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/packs/src/decidim/form_remote.js
decidim-core-0.28.4 app/packs/src/decidim/form_remote.js
decidim-core-0.27.9 app/packs/src/decidim/form_remote.js
decidim-core-0.29.0 app/packs/src/decidim/form_remote.js
decidim-core-0.28.3 app/packs/src/decidim/form_remote.js
decidim-core-0.27.8 app/packs/src/decidim/form_remote.js
decidim-core-0.29.0.rc4 app/packs/src/decidim/form_remote.js
decidim-core-0.29.0.rc3 app/packs/src/decidim/form_remote.js
decidim-core-0.29.0.rc2 app/packs/src/decidim/form_remote.js
decidim-core-0.29.0.rc1 app/packs/src/decidim/form_remote.js
decidim-core-0.28.2 app/packs/src/decidim/form_remote.js
decidim-core-0.27.7 app/packs/src/decidim/form_remote.js
decidim-core-0.28.1 app/packs/src/decidim/form_remote.js
decidim-core-0.27.6 app/packs/src/decidim/form_remote.js
decidim-core-0.26.10 app/packs/src/decidim/form_remote.js
decidim-core-0.26.9 app/packs/src/decidim/form_remote.js
decidim-core-0.28.0 app/packs/src/decidim/form_remote.js
decidim-core-0.27.5 app/packs/src/decidim/form_remote.js
decidim-core-0.28.0.rc5 app/packs/src/decidim/form_remote.js
decidim-core-0.28.0.rc4 app/packs/src/decidim/form_remote.js