Created
March 15, 2024 22:02
-
-
Save joshuafredrickson/89d3899f4a9bcc9215a3eb19b5679b53 to your computer and use it in GitHub Desktop.
Revisions
-
joshuafredrickson created this gist
Mar 15, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; } }, });