solspace / craft-freeform

Freeform for Craft: The most reliable form builder that's ready for wherever your project takes you.
https://docs.solspace.com/craft/freeform/v5/
Other
48 stars 61 forks source link

Submit button Attribute "Disabled" gets removed on page load #1588

Closed svondervoort closed 1 month ago

svondervoort commented 1 month ago

What happened?

Whenever I set the attribute disabled on the submit button through the form configuration it gets removed after a few miliseconds when loading the form in the frontend.

Everything in Settings -> Processing is disabled, so I don't think its ajax.

I can't find anything related in our javascript logic, so is FreeForm doing something with the disabled attribute by any chance?

Errors and Stack Trace (if available)

No response

How can we reproduce this?

  1. Create a form.
  2. Add the disabled attribute to the submit button.
  3. Load the form in the frontend.

Freeform Edition

Pro

Freeform Version

5.6.4

Craft Version

4.12.5

When did this issue start?

Unsure

Previous Freeform Version

No response

gustavs-gutmanis commented 1 month ago

Hi @svondervoort,

Yes, we are handling the disabled state via our front-end plugin javascript. This is necessary for us to be able to provide various integrations and flows which require disabling the form for their duration.

If you would wish to manually manage disabled state, then you could tap into the freeform instance via javascript and manage your disabled state yourself.

Freeform has a namespaced disabled state, meaning that anything can lock the input via a key and unlock it via the same key, and if there are any active locks, the input will still stay disabled, to prevent from accidental unlocks during existing processes.

Here's an example of a simple script which locks the form

(function() {
    const form = document.getElementById("my-form");
    form.addEventListener("freeform-ready", () => {
      // Lock the form
      form.freeform.disableSubmit("my-custom-lock");

      setTimeout(() => {
        // Unlock the form after 5 seconds
        form.freeform.enableSubmit("my-custom-lock");
      }, 5000);
    });
})();
svondervoort commented 1 month ago

Hi @gustavs-gutmanis thanks for sharing. Is this documented somewhere? maybe I just searched for the wrong term in the docs 😅

gustavs-gutmanis commented 1 month ago

This was only used internally, so there's no documentation about it, but since you've shown interest, we will probably write documentation for this.