Last active
June 24, 2021 12:08
-
-
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.
This file contains 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
/** 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. */ |
This file contains 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
<?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