Skip to content

Instantly share code, notes, and snippets.

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 marklchaves/e6e8803a694f8dc13d1c448de01beaf4 to your computer and use it in GitHub Desktop.
Save marklchaves/e6e8803a694f8dc13d1c448de01beaf4 to your computer and use it in GitHub Desktop.
Reposition the Popup Maker "fixed" popup if there are GF form validation errors.
/** Reposition the Popup Maker "fixed" popup if there are GF form validation errors. */
jQuery(document).ready(function($) {
$(document).on('gform_post_render', function(e, formId) {
// Look for the GF validation error container when the GF form is rerendered.
const validationContainer = jQuery(`#gform_${formId}_validation_container`); // or jQuery(`#gform_${formId} .validation_error`);
if (validationContainer.length > 0 ) {
// Get the Popup Maker popup ID.
const popupId = parseInt($(validationContainer).closest('.pum').attr('id').split('-').pop());
// DEBUG
console.log(`%c[PUM] There are validation errors for Gravity Forms form ${formId} in popup ${popupId}.`, 'color:orangered;font-size:16px');
let gfPop = PUM.getPopup(popupId);
// Reposition the popup.
gfPop.popmake('reposition');
} // if
}); // Listener
}); // jQuery
/** Add this script to the footer area of your page. */
<?php // Remove this line when pasting into your child theme's functions.php file.
/** PHP Version */
function my_custom_popup_scripts() { ?>
<script type="text/javascript">
/** Reposition the Popup Maker "fixed" popup if there are GF form validation errors. */
jQuery(document).ready(function($) {
$(document).on('gform_post_render', function(e, formId) {
// Look for the GF validation error container when the GF form is rerendered.
const validationContainer = jQuery(`#gform_${formId}_validation_container`); // or jQuery(`#gform_${formId} .validation_error`);
if (validationContainer.length > 0 ) {
// Get the Popup Maker popup ID.
const popupId = parseInt($(validationContainer).closest('.pum').attr('id').split('-').pop());
// DEBUG
console.log(`%c[PUM] There are validation errors for Gravity Forms form ${formId} in popup ${popupId}.`, 'color:orangered;font-size:16px');
let gfPop = PUM.getPopup(popupId);
// Reposition the popup.
gfPop.popmake('reposition');
} // if
}); // Listener
}); // jQuery
</script><?php
}
add_action( 'wp_footer', 'my_custom_popup_scripts', 500 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment