Created
May 10, 2026 23:15
-
-
Save mishterk/966f2aa4442cb157834d41d9f06c4449 to your computer and use it in GitHub Desktop.
Advanced Forms — workaround for WYSIWYG fields failing to initialise on paginated form pages 2+ (Hookturn ticket #9201). Proper fix queued for AF v1.9.3.9.
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
| /** | |
| * Advanced Forms — WYSIWYG fix for paginated forms | |
| * ---------------------------------------------------------------- | |
| * Workaround for a known bug in Advanced Forms ≤ 1.9.3.8: | |
| * when a WYSIWYG (TinyMCE) field is placed on page 2 (or later) | |
| * of a paginated form, it fails to initialise — the toolbar renders | |
| * but you cannot click into the editor or type. | |
| * | |
| * This snippet hooks Advanced Forms' page-change action and | |
| * re-initialises any visible WYSIWYG editor on the new page. | |
| * Content typed on a previous visit is preserved across page changes. | |
| * | |
| * A proper plugin fix is planned for v1.9.3.9. Once that ships | |
| * this snippet can be removed. | |
| * | |
| * --- How to install --- | |
| * | |
| * Option 1 — Theme functions.php (recommended): | |
| * | |
| * add_action( 'wp_footer', function() { | |
| * if ( ! wp_script_is( 'af-forms-script', 'enqueued' ) ) { | |
| * return; | |
| * } | |
| * ?> | |
| * <script> | |
| * // paste the IIFE below | |
| * </script> | |
| * <?php | |
| * }, 99 ); | |
| * | |
| * Option 2 — A "Code Snippets"-style plugin: paste the IIFE below | |
| * as a frontend snippet (no wrapping <script> tags). | |
| * | |
| * Option 3 — Custom HTML block on the form page itself: paste the | |
| * IIFE wrapped in <script>…</script>. | |
| */ | |
| (function () { | |
| if (typeof window.acf === 'undefined' || !window.acf.addAction) return; | |
| var $ = window.jQuery; | |
| window.acf.addAction('af/form/page_changed', function (page, previousPage, form) { | |
| form.$el.find('.acf-field-wysiwyg').each(function () { | |
| var $field = $(this); | |
| if (!$field.is(':visible')) return; | |
| var fieldInstance = window.acf.getField($field); | |
| if (!fieldInstance) return; | |
| if (typeof fieldInstance.disableEditor === 'function') { | |
| fieldInstance.disableEditor(); | |
| } | |
| // Defer one tick so the layout settles before TinyMCE re-inits. | |
| setTimeout(function () { | |
| fieldInstance.initializeEditor(); | |
| }, 50); | |
| }); | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment