Collapsible fieldsets in Drupal 7 nodes

After struggling with various adoptions for getting collapsible fieldsets to work within nodes for Drupal 7 I came across a final solution.

Make adjustments to template.php (or in a module if you prefer):

function THEMENAME_preprocess_html(&$variables){
// This function looks for node 1 and only adds the javascript for this.
// However it can be extended in different ways if required
    if ($variables['node']['nid'] = 1){
        drupal_add_js('misc/form.js');
        drupal_add_js('misc/collapse.js');
    }
}

In D7 you must also make sure that your legend contains a span with class "fieldset-legend", and that your content is contained in a div with class "fieldset-description", and that you include "misc/form.js" for your javascript. Then it’ll work.

Example

<fieldset id="fieldset-id" class="collapsible">
<legend><span class="fieldset-legend">Fieldset title</span></legend>
<div class="fieldset-wrapper">
<div class="fieldset-description">Fieldset description</div>
Fieldset content
</div>
</fieldset>

Image

Collapsible fieldsets in Drupal 7 nodes

Comments

Submitted by man (not verified) on

Zest is the secret of all beauty. There is no beauty that is attractive without zest.
<a href="http://www.kids-flix.com">movie kids</a>

Submitted by gippy (not verified) on

It's hard to tell with these Internet startups if they're really interested in building companies or if they're just interested in the money. I can tell you, though: If they don't really want to build a company, they won't luck into it. That's because it's so hard that if you don't have a passion, you'll give up.
<a href="http://personalvpnreviews.com">VPN reviews</a>

Pages

Add comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.