Last active
July 1, 2025 14:52
-
-
Save MjHead/498cc91d002991c9a4acfe05ea353c39 to your computer and use it in GitHub Desktop.
JetFormBuilder. JS. Do something while form is submitting
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 characters
<script> | |
document.addEventListener( 'DOMContentLoaded', function() { | |
if ( ! window.JetPlugins ) { | |
return; | |
} | |
const $forms = document.querySelectorAll( '.jet-form-builder' ); | |
if ( ! $forms.length ) { | |
return; | |
} | |
// Tracks start of the form processing | |
$forms.forEach( function( $form ) { | |
$form.addEventListener( 'submit', function( event ) { | |
// Here we're doing what we need on submit start | |
event.target.style.backgroundColor = 'red'; | |
} ); | |
} ); | |
// Callback performed on the end of the form processing | |
function onFormSubmit() { | |
// Here we're doing what we need on submit end | |
this.formNode.style.backgroundColor = 'transparent'; | |
} | |
// Tracks end of the form processing | |
window.JetPlugins.hooks.addAction( 'jet.fb.observe.after', 'checkStart', function( observable ) { | |
observable.form.submitter.status.formNode = observable.rootNode; | |
observable.form.submitter.status.watch( onFormSubmit ); | |
} ); | |
} ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment