diff --git a/lib/Horde/Form/Renderer.php b/lib/Horde/Form/Renderer.php index 0e04d8d..ec93f5c 100644 --- a/lib/Horde/Form/Renderer.php +++ b/lib/Horde/Form/Renderer.php @@ -146,15 +146,28 @@ public function _renderSectionTabs($form) /* Add the javascript for the toggling the sections. */ $page = $GLOBALS['injector']->getInstance('Horde_PageOutput'); - $page->addScriptFile('form_sections.js', 'horde'); - $page->addInlineScript( - sprintf( - 'var sections_%1$s = new Horde_Form_Sections(\'%1$s\', \'%2$s\');', - $form->getName(), - rawurlencode($open_section) - ) + $var_name = 'sections_' . $form->getName(); + $var_script = sprintf( + 'var %1$s = new Horde_Form_Sections(\'%2$s\', \'%3$s\');', + $var_name, + $form->getName(), + rawurlencode($open_section) ); - + + /* Output script inline in body to ensure it's loaded synchronously before variable initialization */ + /* Note: Even though scripts in header are loaded synchronously, there can be timing issues + * when the variable is initialized in the body. Inline embedding guarantees the script + * is available immediately when the variable is initialized. */ + $script_path = $GLOBALS['registry']->get('jsfs', 'horde') . 'form_sections.js'; + if (file_exists($script_path)) { + $script_content = file_get_contents($script_path); + echo '' . "\n"; + } + /* Loop through the sections and print out a tab for each. */ echo "