Fieldsets with #collapsible=TRUE don't work correctly and mix up the sub-elements order in certain situations. The bug appears when inserting theme('filter_tips', ...) into the #description of a form element.

The FAPI code below makes the "input formats:" text of drupals standard theme move to the bottom of the fieldset. When collapsing the fieldset, the text moves out of the fieldset.


    // get filter tips and set fieldset parameters
    $filter_tips_wrapper = array(  
      '#title' => t('Formatting hints'),  
      '#collapsible' => TRUE, // define as collapsible. If not, the bug won't appear!
      '#collapsed' => TRUE,
      '#value' => theme('filter_tips', _filter_tips(-1, FALSE), TRUE),                            
    );  
    
    $newmail_form['newmail']['body'] = array(
      '#type' => 'textarea',
      '#title' => t('Your Message'),
      '#cols' => 60,
      '#rows' => 8,
      '#weight' => 3,
      '#required' => true,    
      '#description' => theme('fieldset', $filter_tips_wrapper), // put the fieldset into mail body description
      '#default_value' => $preview_body,
    );

I think it's a javascript bug of FAPI.

Comments

Anonymous’s picture

A quick fix is to put all fieldset content into <div> like

      '#value' => '<div>'.theme('filter_tips', _filter_tips(-1, FALSE), TRUE).'</div>',
catch’s picture

Version: 6.2 » 7.x-dev

Yeah the current fix is to put any text into a div. I'm not sure if there's a duplicate issue, but this will need to be fixed against HEAD then backported, so moving there for now.

edmund.kwok’s picture

In line 75 of collapse.js

.append(fieldset.children(':not(legend):not(.action)')))

Hmm, it seems that the text 'input formats:' is left out of the fieldset because it is not enclosed in any tags. I'm not very sure about DOM, but I think since the text is not in any tag, it is not considered a child of the fieldset. So one possible fix that is specific to your case is to overwrite theme_filter_tips and enclose the text in a tag.

For a general fix in core, I'm not sure what if there is any function to obtain the text which is not considered a chid. Perhaps a guideline can be provided stating that any text in a collapsible fieldset should be enclosed in a tag?

casey’s picture

Version: 7.x-dev » 6.x-dev

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.