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:
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
If still doesn't work, you may try
or
Thanks, worked for me!
Thanks, worked for me!
Actually, the best way to do
Actually, the best way to do this is:
-Pol-
https://not-a-number.io/
To tie into the API I'd do it
To tie into the API I'd do it like this:
Nope, this doesn't work. You
Nope, this doesn't work. You must include manually the classes.
-Pol-
https://not-a-number.io/
Ok, good to know. I'm
Ok, good to know. I'm guessing that the fieldset needs to be part of a form for #collapsed and #collapsible to work.
Only in forms
Thanks for this hint!
I confirm, the form_process_fieldset() is only called if the fieldset is within a form.
So the classes and the library must be added manually if outside a form.
in which file do i have to
in which file do i have to add this lines?
An even cleaner way
Calling the
theme()
function directly or using a renderable array outside of a form does not work because it doesn't invoke Drupal's form element#process
code on the fieldset.An even cleaner way to do this is to call Drupal's form element
#process
on the renderable array.This will leave
$fieldset
as a renderable array with all of the proper classes set and the required libraries attached.Adding:
Adding:
to the
$fieldset
array will prevent a warning about#parents
not being set, thrown byform_process_field