Created
July 14, 2023 13:26
-
-
Save santanup789/d4f4dc22a49c91bbd764e9df02925d9a to your computer and use it in GitHub Desktop.
Step form auto trigger next in Gravity form
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
<script> | |
jQuery(function($){ | |
$( document ).on( 'elementor/popup/show', (event, id, instance) => { | |
if ( id === 2063 ) { | |
setTimeout(function(){ | |
if($('#elementor-popup-modal-'+id+' .gform_wrapper').length){ | |
var formID = $('#elementor-popup-modal-'+id+' .gform_wrapper form').attr('data-formid'); | |
console.log('gfrom found'); | |
$('form[id^="gform_'+formID+'"]').on('change', function (e) { | |
var getCurrentPage = $('#gform_source_page_number_'+formID+'').val(); | |
console.log('changed'); | |
setTimeout(function(){ | |
$('#gform_page_'+formID+'_'+getCurrentPage+' .gform_next_button').trigger('click'); | |
}, 200) | |
}) | |
$(document).on('gform_page_loaded', function(event, form_id, current_page){ | |
$('form[id^="gform_'+formID+'"]').on('change', function (e) { | |
setTimeout(function(){ | |
$('#gform_page_'+formID+'_'+current_page+' .gform_next_button').trigger('click'); | |
}, 200) | |
}); | |
}) | |
} | |
}, 100); | |
} | |
}); | |
}) | |
</script> | |
// in my case I need to display to form in a popup and i'm using elementor popup to display the popup. | |
// There is no JS hook to check the gravity form loading status and as well as in step form we can't check the 1st step until we press the next or previous button. | |
// To overcome that issue, I mean to check if the 1st step is displaying when the form is being displayed I've used some in build information from the gravity form's HTML. | |
// I need to get the form id I've placed inside the popup. So, I took a variable "formID" and tried to fetch the form id from and data sttribute the gravity form gave in the HTML. | |
// Then I'm checking when the form data is being changed for the 1st step. | |
// As I told you for the 1st step we can't fetch the current step. So, in another HTML part inside the gravity form, we can get the current step number is visible. | |
// Once one option is selected a setTimeout function fired to trigger the next button. Once the 1st step complete now we can get the current page number from the gravity form itself. | |
// So, again the same onChange function called inside the "gform_page_loaded" function. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment