Community & Support

Expanding or collapsing fieldsets by default

I've been trying to figure out how to have fieldsets collapsed or expanded by default on various forms. The page to add a new node for example has several fieldsets such as "Menu settings", "Input Format", etc. Some are expanded by default and some are collapsed. I want to be able to control which ones are expanded by default. So far as I can tell the best way to do this is to override the form in the template.php file with a function that sets the collapsed value to 1 or 0 for that fieldset. However when I implement such a function it doesn't seem to work properly:

function visualdxhealth_node_form($form) {
$output = '';

$form['path']['#collapsed'] = 1;

$output .= drupal_render($form);
 
return $output;
}

Should this work and is there a better way to achieve this?

Comments

Forms API

http://api.drupal.org/api/file/developer/topics/forms_api.html

You need to set the collapsed attribute to TRUE using the D6 methods.

That does make the fieldset

That does make the fieldset collapsed by default. However the placement of the Preview and Submit buttons for a node creation page change. They move from the bottom where they normally are to below the Input Format fieldset. Any idea what would cause that?

In case anyone else is

In case anyone else is looking for a solution to the placement of the Preview and Submit buttons, this code works:

// Force the submit buttons to the bottom of the page
$form['buttons']['#weight'] = '99';
nobody click here