i would like to act on the field group --specifically hide and show fieldgroups programatically with JQuery, but where i can hide/show individual fields b/c they have id's as part of their element, fieldgroups only have the class attribute. can we add an auto-gen'd id attribute to fieldgroups, so they can be acted on like other elements.

Or, does anyone know a way to collapse/expand a fieldgroup in JQuery based on the toggle (click) of a checkbox (have it working for hide/show text field, but not fieldgroup).

thanks,
mark

Comments

marqpdx’s picture

So i found out where in the code it goes:
in the fieldgroup.module, the fieldgroup_form_alter() function, near line 301, i added the following:

old:

 '#attributes' => array('class' => strtr($group['group_name'], '_', '-')),

and new:

 '#attributes' => array('class' => strtr($group['group_name'], '_', '-') , 'id' => 'fieldset_' . $group['group_name']),

It's a very simple change and adds a good bit of consistency and potential for acting on fieldgroups.

Don't exactly know how to patch, but it's easy enough to add.

thx,
m

smitty’s picture

Well, I think, the class-Attribute is very special here. Could it be, that it was originally meant to be an id, and wrongly named "class"?

For working with css it would be nice to have a class-attribute, wich is the same for all fieldgroups. So I propose to change the line to:

'#attributes' => array('class' => strtr($group['group_name'], '_', '-'  . ' cck-fieldgroup') , 'id' => 'fieldset_' . $group['group_name']),
g76’s picture

Did this work for you?

I have been looking for a solution myself. I need to display a background image using css for a fieldgroup, not just individual fields. I have a "pricing" fieldgroup with 2 fields included: price per month, and setup fee. I need both fields and the image behind the whole group, but no class or id to reference with css.

-thanks,
Jen

markus_petrux’s picture

There are different options to display a fieldgroup that you can choose from "Display fields". Each method uses a unique class name derived from the group name (underlines are converted to hyphens). This unique class name could be used as a jQuery selector. The HTML elements used are DIV or FIELDSET, which is also a hint.

Also, if you use the 'simple' display option, you can then override the template. The default one is shipped in the fieldgroup module folder: fieldgroup.tpl.php

If you need any of the 'fieldset' display options, then you can override theme_fieldgroup_fieldset (default is in fieldgroup.module) from your theme.

markus_petrux’s picture

Status: Active » Closed (won't fix)

We cannot add id because these should be unique in the DOM, and we may be rendering thge same fieldgroup several times on a single page, using Panels for example. So unique ID per group is no go in CCK. That doesn 't mean it can be done in custom module, as described in #4.