Skip to content

Instantly share code, notes, and snippets.

@jetsloth
Created September 15, 2020 11:38
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 jetsloth/bdea1a486555e73d55e2754e05964362 to your computer and use it in GitHub Desktop.
Save jetsloth/bdea1a486555e73d55e2754e05964362 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
(function($){
// update this value as needed
var scrollOffset = 30;
$(document).bind('gform_post_render', function(e, formId, currentFormPage) {
var $form = $('#gform_' + formId);
if ( $form.hasClass('auto-advance') && !$form.hasClass('auto-advance-init') ) {
$form.find('.gsection').not(':first').each(function(){
var $section = $(this);
$section.addClass('inactive');
if ( $section.hasClass('collapsible-sections-field') ) {
$section.next('.collapsible-sections-collapsible-body').addClass('inactive');
}
else {
$section.nextUntil('.gsection').addClass('inactive');
}
});
$form.find('.gform_footer input:submit, .gform_footer button').addClass('inactive').prop('disabled', true);
var firstRun = true;
$form.find('input:radio').on('change', function(e){
var $input = $(this);
if ( $input.is(':checked') ) {
var $field = $input.closest('.gfield');
var $nextSection;
var nextSectionScrollDelay = 10;
if ( $field.closest('.collapsible-sections-collapsible-body').length ) {
$nextSection = $field.closest('.collapsible-sections-collapsible-body').nextAll('.gsection').first();
}
else {
$nextSection = $field.nextAll('.gsection').first();
}
if ( $nextSection.length ) {
$nextSection.removeClass('inactive');
if ( $nextSection.hasClass('collapsible-sections-field') ) {
$nextSection.next('.collapsible-sections-collapsible-body').removeClass('inactive');
nextSectionScrollDelay = 500;
if ( !firstRun ) {
$nextSection.trigger('click');
}
}
else {
$nextSection.nextUntil('.gsection').removeClass('inactive');
}
if ( !firstRun ) {
setTimeout(function(){
var targetTop = $nextSection.offset().top - scrollOffset;
$('html,body').animate({ scrollTop: targetTop }, 300);
}, nextSectionScrollDelay);
}
if ( !$nextSection.nextAll('.gsection').length ) {
$form.find('.gform_footer input:submit, .gform_footer button').removeClass('inactive').prop('disabled', false);
}
}
}
}).trigger('change');
$form.addClass('auto-advance-init');
setTimeout(function(){
firstRun = false;
}, 500);
}
});
})(jQuery);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment