Community

Fieldsets in D7, collapsed and collapsible not working

For some reason I cannot get the theme_fieldset function to make me a collapsible or collapsed fieldset.

This code:

$page['xyz'] = theme('fieldset', array('element' => array('#title' => 'XYZ', '#value' => $xyz, '#collapsed' => TRUE, '#collapsible' => TRUE)));

should as far as I can see from the docs give me a collapsible fieldset starting out collapsed.
http://api.drupal.org/api/drupal/includes--form.inc/function/theme_field...

It gives me a fieldset, but neither collapsed nor collapsible.

Wondering why...

I can't find any examples online, and honestly; looking in the code I can't see where the theme function actually checks for these parameters and creates the fieldset appropriately. Looking through my D7 installation, I find one reference to theme_fieldset or theme('fieldset' ...), apart from in my own code, and that's in form.inc where the function is declared.

Am I theming the fieldset the completely wrong way?

Martin

Comments

Hi, you also have to

Hi,

you also have to include the collapse library for d7. You can do it like this:

drupal_add_library('system', 'drupal.collapse');

Vasi.

Vasi, Thanks for the tip! I

Vasi,

Thanks for the tip! I didn't realize that... but unfortunately that doesn't quite do it.

The behavior of the fieldset remains the same: no behavior. But I did get the small arrows that indicates collapsible sections, so something has happened.

But going into a little js debugging I notice that I get this error when the library is included:

"Error: uncaught exception: Syntax error, unrecognized expression:"

when the page loads. It seems to come from jQuery. FireFox has no further information while IE tells me that it stems from jquery.js itself. I have no idea what causes this.

I'll dig into this and see where it leads me.

Thanks for your help.

Martin

me too subscr

me too
subscr

I see that does not

use '#collapsible' and '#collapsed' parameters the theme_fieldset() function.

I was wrote a patch, it is failed in test but works fine for me.
Thread is here: http://drupal.org/node/1099132
If somebody knows what is the problem with this patch please let me know too.

Regards,
Joe

Collapsible fieldsets using drupal_render

This code works for me

<?php
$renderable
['fieldset'] = array(
 
'#type' => 'fieldset',
 
'#title' => t('Title'),
 
'example content' => array (
   
'#theme' => 'item_list',
   
'#items' => array(
     
t('Example item')
    )
  ),
 
'#attributes' => array (
   
'class' => array(
     
'collapsible', 'collapsed'
   
)
  )
);

drupal_render($renderable);
?>

If still doesn't work, you may try

<?php
drupal_add_library
('system', 'drupal.collapse');
?>

or
<?php
drupal_add_js
('misc/form.js'); // don't know if its really required to collapsible fieldsets to work
drupal_add_js('misc/collapse.js');
?>

--
Tomasz Dąbski "CzarnyZajaczek"
http://www.itlublin.pl

nobody click here