Skip to content

Instantly share code, notes, and snippets.

@joshuafredrickson
Created March 15, 2024 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuafredrickson/89d3899f4a9bcc9215a3eb19b5679b53 to your computer and use it in GitHub Desktop.
Save joshuafredrickson/89d3899f4a9bcc9215a3eb19b5679b53 to your computer and use it in GitHub Desktop.
Gravity Forms: Perform an action while the form is submitting
/**
* 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;
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment