? Form API: Vertical Tabs attached library fix: http://drupal.org/node/551426
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.442
diff -u -p -r1.442 form.inc
--- includes/form.inc	13 Mar 2010 22:33:05 -0000	1.442
+++ includes/form.inc	17 Mar 2010 15:44:44 -0000
@@ -2361,7 +2361,7 @@ function form_process_container($element
  */
 function theme_container($variables) {
   $element = $variables['element'];
-  if (!isset($element['#attributes']['id'])) {
+  if (!isset($element['#attributes']['id']) && isset($element['#id'])) {
     $element['#attributes']['id'] = $element['#id'];
   }
   // Force the 'form-wrapper' class.
@@ -2638,6 +2638,17 @@ function form_process_vertical_tabs($ele
 }
 
 /**
+ * Post render on the Vertical Tabs to add the JavaScript library.
+ */
+function form_post_render_vertical_tabs($children, &$element) {
+  // Only add the JavaScript library if there are child tabs.
+  if (!empty($element['group']['#children'])) {
+    $element['#attached']['library'][] = array('system', 'vertical-tabs');
+  }
+  return $children;
+}
+
+/**
  * Makes the element's children fieldsets be vertical tabs.
  *
  * @param $variables
@@ -2652,10 +2663,18 @@ function form_process_vertical_tabs($ele
  */
 function theme_vertical_tabs($variables) {
   $element = $variables['element'];
-  // Add required JavaScript and Stylesheet.
-  drupal_add_library('system', 'vertical-tabs');
 
-  return '<div class="vertical-tabs-panes">' . $element['#children'] . '</div>';
+  // Only return HTML if there are child tabs.
+  if (!empty($element['group']['#children'])) {
+    // The "vertical-tabs-panes" class will allow the JavaScript to process it.
+    $element['#attributes']['class'][] = 'vertical-tabs-panes';
+    return theme('container', array(
+      'element' => array(
+        '#attributes' => $element['#attributes'],
+        '#children' => $element['#children'],
+      ),
+    ));
+  }
 }
 
 /**
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.901
diff -u -p -r1.901 system.module
--- modules/system/system.module	13 Mar 2010 06:55:50 -0000	1.901
+++ modules/system/system.module	17 Mar 2010 15:44:59 -0000
@@ -465,6 +465,7 @@ function system_element_info() {
     '#theme_wrappers' => array('vertical_tabs'),
     '#default_tab' => '',
     '#process' => array('form_process_vertical_tabs'),
+    '#post_render' => array('form_post_render_vertical_tabs'),
   );
 
   $types['container'] = array(
