Skip to content

Instantly share code, notes, and snippets.

@joshuafredrickson
Created March 15, 2024 22:02
Show Gist options
  • Select an option

  • Save joshuafredrickson/89d3899f4a9bcc9215a3eb19b5679b53 to your computer and use it in GitHub Desktop.

Select an option

Save joshuafredrickson/89d3899f4a9bcc9215a3eb19b5679b53 to your computer and use it in GitHub Desktop.

Revisions

  1. joshuafredrickson created this gist Mar 15, 2024.
    26 changes: 26 additions & 0 deletions gravity-forms.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    /**
    * Hook into the Gravity Forms submission process to show a loading state
    */

    const wrapper = document.querySelector(
    '.gform_wrapper'
    );
    const gfSubmitting = `gf_submitting_${
    wrapper.querySelector('form').dataset.formid
    }`;
    let formSubmitting = false; // Private variable to hold the state

    // Create computed properties for the "gf_submitting_{id}" property
    Object.defineProperty(window, gfSubmitting, {
    get() {
    return formSubmitting;
    },
    set(newValue) {
    if (formSubmitting !== newValue) {
    formSubmitting = newValue;
    // Do something when the state changes
    // Here, we're dialing down opacity while the AJAX spinner is spinning
    wrapper.querySelector('.gform-body').style.opacity = newValue ? 0.3 : 1;
    }
    },
    });