Created
September 15, 2020 11:38
-
-
Save jetsloth/bdea1a486555e73d55e2754e05964362 to your computer and use it in GitHub Desktop.
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 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