Expanding or collapsing fieldsets by default

logicalpat - January 13, 2009 - 20:34

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?

Forms API

gbrussel - January 13, 2009 - 20:42

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

logicalpat - January 13, 2009 - 20:47

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?

 
 

Drupal is a registered trademark of Dries Buytaert.