Created
July 28, 2025 04:26
-
-
Save aliboy08/b2478eb23b2e610c6476557b9dd61861 to your computer and use it in GitHub Desktop.
gravityforms multistep with conditions validation issue fix (shows headings of inactive pages)
This file contains hidden or 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
| init(); | |
| function init(){ | |
| document.addEventListener( 'gform/post_render', (e)=>{ | |
| const { formId, currentPage } = e.detail; | |
| if( formId !== 10 ) return; | |
| init_custom_steps_validation(formId, currentPage); | |
| }); | |
| } | |
| function init_custom_steps_validation(form_id, page_id){ | |
| const page = document.querySelector(`#gform_page_${form_id}_${page_id}`) | |
| if( !page.querySelector('.gfield_error') ) return; | |
| hide_inactive_headings(form_id); | |
| } | |
| function hide_inactive_headings(form_id){ | |
| const headings = document.querySelector(`#gf_page_steps_${form_id}`) | |
| const pages = document.querySelectorAll(`#gform_${form_id} .gform_page`); | |
| pages.forEach((page, index)=>{ | |
| const heading = headings.childNodes[index]; | |
| heading.style.display = page.dataset.conditionalLogic === 'hidden' ? 'none' : ''; | |
| }) | |
| fix_steps_index(headings) | |
| } | |
| function fix_steps_index(headings){ | |
| let index = 1; | |
| headings.childNodes.forEach(heading=>{ | |
| const num = heading.querySelector('.gf_step_number') | |
| if( !num.offsetParent) return; | |
| num.textContent = index; | |
| index++; | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment