/** * 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; } }, });