I'm using field_permission to hide fields to users without proper role and this brought a fieldset to be empty for certain users.
BTW the fieldset itself is shown even with no fields in it.
I think should check that user could see at least one field before rendering a fieldset.
I had a look at the module code, and I've seen there's a function called field_group_field_group_is_empty, but it just checks if a group has children, not if user can see them.

Members fund testing for the Drupal project. Drupal Association Learn more


valderama’s picture

Same applies if a field is display conditionally (with field_conditional_state) - that might also result in empty fieldsets|tabs ...

info about field_conditional_state module is currently here:

SilviaT’s picture

Is there a way to hide these fieldsets programmatically if empty?

GloGi’s picture


Stalski’s picture

Programmatically I'd expect those module would alter the #access attribute. As mentioned above, field group is empty only checks if it's empty, however, fields that have an access false are not put into the tree of fieldgroups.
I'll check how field_permission does his thing, however pity that the built-in check for this does not trigger those type of fields.

Stalski’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
Assigned: Unassigned » Stalski
Status: Active » Needs review

I Added a fix on processed fields. It seems like the safest choice there.
Could everyone here test this please?

- Edit - It's in git (no patch)

spacereactor’s picture

I using the field_group 7.x-1.0 and it still having this problem

juves’s picture

Yep, after update it's back again.

Stalski’s picture

7.x-1.0 should not have that problem after updating (and clearing cache)
@spacereactor: Still have the problem after updating?
if so, please provide steps to reproduce this.

GloGi’s picture

I confim. Updated from 7.x dev to 7.x-1.0, cleared the cache atleast 3 times and the problem still exists.

Heres an example of my field groups

Manage fields:
- Group1 - Vertical tabs group
-- group2 - vertical tab
--- Textfield
--- Date field
--- Text field
-- group 2 - Vertical tab
--- textfield
--- etc...
--- etc....

Display fields:
Custom display settings: Full content
- Group1 - Fieldset - open
-- group2 - Fieldset - open
--- Textfield
--- Date field
--- Text field
-- group 2 - Fieldset -open
--- textfield
--- etc...
--- etc....

kingjohnnet’s picture


GloGi’s picture

Status: Needs review » Needs work

Bumping this up to needs work, since the bug is still there.

Stalski’s picture

I changed to code again, and it (still) works here. Due to some other bug fields were not showing, I had to take another approach.
I am still testing this, but already did another solution in git. Can anyone test this please?
thx in advance.

Stalski’s picture

Status: Needs work » Needs review

pushed and ready for testing. (in git repository)

juves’s picture

Field group: May 28, 2011 - 02:12 doesn't solve the problem for me

Stalski’s picture

Title: Fieldset displayed even if empty » Fieldset displayed even if empty (E.g. field_permission)

I really don't get what is going on now.
Can you explain the case you have? entity and type? form or view mode? things like that.
Thanks in advance

GloGi’s picture

I'll try to explain my case as detailed as I can. So here goes nothing.

I want to do a one content type which is used to create reviews like video, music, books and etc. So that when I write for example video review I can just write the videos info to those field which are under Video vertical tab. And after submitting the review iI want it to only show me info in this structure.

Info - fieldset
- Image
- Video -fieldset
-- what ever fields that has been filled.
-- etc.

But now after submit it renders it like this

Info- fieldset
- Image
- Video - fieldset
-- filled fields
-- etc.
- Music - fieldset
- Book - fieldset
- Etc. - fieldset

Stalski, if you want, PM in here/irc I'll give you access to test site where I have done that.

juves’s picture

I use HTabs on an custom content type for displaying fields to users (view mode)



I just noticed that all my HTabs in HTgroup were changed to Vtabs after update to 1.0.final (now I use latest dev). I changed it back, but it didn't help.

Stalski’s picture

Latest dev is the one you should use for now (not dev but from git best in this case)
The only thing changed there, is a fix for empty groups on forms. The function that you could debug in is "field_group_remove_empty_groups"

- Edit -
My test case where it works is as follows:
- Content type "field_permissions" has two fields: auth_text and editor_text. The field_permissions for these fields are set to corresponding to authenticated and editor role.
- I have a editor user, having the editor role and authenticated person who is a normal authenticated user.
- As authenticated, I don't see the vertical tab "editor_text_group" where the editor_text is located.

So I think this should cover the same thing as your use cases

Stalski’s picture

Screenshots to show my simple use case

juves’s picture

I don't use Field Permissions, I don't think it's related. The Problem is - fieldgroups are always displayed, do they have content or not.

Stalski’s picture

Yes but the tricky part is there I need to know the reasons why content is not there.
1/ a field inside a field group is denied through field_permission module or some alike thing: the child elements of a root element will not be present in the array. Action taken accordingly.
2/ a field group is created by nothing is nested inside: Field group will check if it has children.
3/ a field is denied by some code through the #access variable of a field: again fieldgroup drops out these elements so it will fallback in the 1/ and 2/

+ this is totally different in forms and in rendered view modes as forms can have "empty" content of a field.

These is the short summary of the problems that field group has. So, in all of the cases described above, it's working for me.

Your problem, is thus not on forms but in rendered view mode, I persume, otherwise content can be left out ofcourse.

juves’s picture

There was no problems with Field Group for me with dev version from end of March, why it appears after update to 1.0?

Stalski’s picture

I still have no problems at all. Somebody else?

spacereactor’s picture

8.15 KB
5.95 KB
13 KB
5.56 KB
76.27 KB

I using 7.x-1.x-dev (29 may) and display suite. Flush all caches before testing.

See photo 1.
I insert 3 views into into field group (group_tabs_gallery / group_tabs_news / group_tabs_download) and 1 comment (group_tabs_brochure)

See Photo 2.
Insert a Views into group_tabs_gallery, there no content inside the views, but it still display the "Gallery" tabs. I hope that this tabs doesn't display if there no views content.

See Photo 3.
Insert a Views into group_tabs_news, which have a post and it does show up correctly.

See Photo 4.
Insert a Comment into group_tabs_brochure, but there no comment yet the tabs still display the empty content "Brochure" tabs. I hope that this tabs doesn't display if there no comment or cck content.

See Photo 5.
Insert a Views into group_tabs_download, there no content inside the views but i add "NO RESULTS BEHAVIOR" at views setting to show "Currently no content", "Download" tabs display with the "Currently no content" as content. I just want to test if there any change by add NO RESULTS BEHAVIOR in views.

Is that how field group suppose to work? I kind of expecting no content inside the tabs, the tabs doesn't display at all.

jeffrey.dalton’s picture

Confirming: I have horizontal field group with 3 horizontal tabs each containing file fields. I am using the full 7.x-1.0 release. (this ticket is marked dev but figured it was more relevant to add here than start a new ticket)

In the node--investor.tpl.php file I am doing:

<?php if (isset($content['group_investor_reports'])): ?>
  <div class="investor-reports">
    <?php print render($content['group_investor_reports']); ?>
<?php endif; ?>

The node has no content assign to these fields but I am getting the full horizontal field group and each tab though they are all empty.

Expected behavior would be individual tabs do not render if they are empty and the whole tab group does not render if all tabs are empty. I would swear this was working in the release candidate?

bdurbin’s picture

An example $element data structure we're getting for an "empty" horizontal tab group in field_group_field_group_is_empty() is:

$element = array(
  'group_name' => array(
    'field_name_1' => NULL // I'm not in $groups, but I'm NULL
    '#attribute1' =>'blah'

The assumption that if a child element exists, and isn't a group, that it's a field with data appears to be incorrect. Perhaps the actual issue is with populating fields beneath their respective groups if those elements are going to end up NULL? In any case, the attached patch seemed to solve our issue.

The content type configuration in our case is:

- horizontal tab group
-- horizontal tab item 1
--- field 1 (multi-valued "generic file" field)
-- horizontal tab item 2
--- field 2 (multi-valued "generic file" field)
-- horizontal tab item 3
--- field 3 (multi-valued "generic file" field)
-- horizontal tab item 4
--- field 4 (multi-valued "generic file" field)

GloGi’s picture

71.24 KB

This didn't work for me alltough it sounds the right way to go and the code looks good to me. Here's a picture attached of what I am getting with textfields.

reptilex’s picture

I can confirm the issue, first I had the bug described in http://drupal.org/node/1169146 . After that I now see my fieldgroups even if they are empty.

I have read the problems stated, and to me it sounded as if it was allways related to entities other than normal node fields. I read about files, images and I have a profile2 entity. Maybe it is related to how this work differently than normal nodes?

I did not apply any git patch, just the latest fieldgroup 1.0 version from today. You even get a pic ;)

spacereactor’s picture

#26 patch doesn't work for me. using 7.x-1.x-dev 2011-May-29

To Stalski
I not sure if we are on the same page. I using field group for node reference. So there are some empty field group because there isn't node reference attach to the node yet. So i do hope it does hid all empty field group.

kehan’s picture

subscribing and #26 works for some fieldsgroups but not all, I still can't work out which ones tho.

spacereactor’s picture

Title: Fieldset displayed even if empty (E.g. field_permission) » Fieldset displayed even if empty

just update Field group 7.x-1.x-dev 2011-Jun-11 problem still remain. Field group still display even when the content is empty.

spacereactor’s picture

Title: Fieldset displayed even if empty » Fieldset displayed even if there is no content

change title

bdurbin’s picture

Here's the other half of the patch from #26. This is against dev again, and the code there appears to be moving on, but a similar patch against 7.x-1.0 is working for us. The first part of the patch, from #26 correctly identifies "empty" fields within the group. The new part detects whether or not a given field is present on the render element before adding it to the appropriate group.

Note: This just solves our particular use case and hasn't been more generally tested. I'm offering this up in case it happens to be the general fix, or helps the module maintainer narrow down the conditions posters in this thread are experiencing.

- The entire tab group does not display display if all tabs in a group are empty
- Tabs within a group that don't have content are not displayed.

spacereactor’s picture

#33 patch remove the empty tabs in the display section. Thank-you!! Hope Stalski and the team have a permanent solution.

GloGi’s picture

#33 Nice, this works great! Thanks.

Dippers’s picture

#33 fixes some of my problems but not all of them.
I'm using an accordion with accordion items so the items (which are also groups) are nested. field_group_field_group_build_pre_render_alter only seems to get called when the parent element (in my case the user profile) is being rendered. This element only has one child, the accordion. The accordion items are checked to see if they are not empty and if any are not empty the accordion is marked as not empty and the hook exits.
There appears to be no way to itterate through nested groups to remove empty accordion items.

Stalski’s picture

I waited a little to see how this issue was scattering problems of the same type but in other cases, entities, etc ...
Before #23, I have tried so many things just to do something I don't find in core (is the field to be displayed?) . There are lots of reasons appearantly why a field is not displayed.
- it's access property
- the field_access callback
- field is empty all of a sudden
- the field is empty however it has children ([0] item)

so I will check the patch in #33 since most people are satisfied.
That leaves me with reproduction steps.
As I see only @Dippers still has problems, is it possible to have your setup? Maybe in feature form or the exports ...
Thx everyone for all the feedback. This has top priority.

Stalski’s picture

I already committed the patch to dev since I can only see good from it.

Dippers’s picture

How to reproduce empty group display:
1. Create an accordion group in an emtpy content type in 'manage display'
2. Add three accordion items to the group
3. Move 'Body' field into accordion item 1
4. Create a fieldset group and place in accordion item 3
5. Create a node of given content type - add something to body
6. View node. Accordion will show with item 1 containing body text, item 2 missing because it is empty and item 3 will be shown but empty as it only contains an empty fieldset.

Other observations.:
Move Body out of item 1 and none of the accordion items are shown.
Above still fails if fieldsets rather than accordion are used. Have one fieldset group with three children fieldsets. Add body to first child and add empty fieldset to third child. View node and you will see empty fieldset.

As mentioned in previous posts I believe the problem is because nested groups are not itterated through looking for empty groups. Either all groups should be checked for being empty BEFORE calling fields_nest or the group tree needs to be walked through looking for empty groups.

Dippers’s picture

I should say #39 is a trivial case and the third level fieldset remains shown but empty if inaccessible fields are added to it.

zuuperman’s picture

Thx Dippers for your steps. I reconstructed it locally and found a fix. This is now committed to dev.

Stalski’s picture

Status: Needs review » Fixed

Nice work. The steps to reproduce were very usefull!
The upgrade on the function to check empty groups works great.

Dippers’s picture

I'm getting function 'field_group_field_group_is_empty' not found on line 804 of field_group.module on the latest dev.
Change it to 'field_group_remove_empty_display_groups' and it works fine and fixes #39.

zuuperman’s picture

Sry for the undefined function :)

Tested all, and renamed the function after testing, but forgot to re-test :).
Fix has been committed.

bryancasler’s picture

I was playing around with the latest git version and all of my fields inside field groups disappeared. I believe this commit is responsible.


If I undo this commit my field groups re-appear

bryancasler’s picture

I had to find a quick work around to hide empty field groups. For the interim here is a bit of JS that will do just that.


Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mirsoft’s picture

Status: Closed (fixed) » Active
1.06 KB

Actually, the 2011-Jun-22 dev version fixed most of "empty groups" issues, but not all. For example, these fields have not been considered as "empty" to me:

- empty field of type "Long text and summary" (inserted one empty <br/> tag by default, which prevents Field Group to treat this field as empty)
- block field from Display suite (e.g. views block with some images) with zero records

These situations left always some markups inside, even though they have in fact been empty.

Therefore I created patch which fixed these issues to me. Together with simple checking if the field is empty, it also goes deeper - it looks inside field's markup, strips HTML tags (except tags <img> and <embed>, to not strip images and flash videos), trims resulting field for spaces/newlines and only if something still remains in the result, the field is considered as not empty.

zuuperman’s picture

Status: Active » Closed (works as designed)

Long text and summary don't insert a
tag by default.

Stripping html to check if empty, is a bit dangerous. There are a lot more tags (and coming). example video. Blocks module also doesn't do this. If a block returns only html, core will show this.

peezy’s picture

Switching to 7.x-1.x-dev worked for me. #48 ended up hiding my image fields, even when the had images in them.

bryancasler’s picture

Cross-posting a similar discussion happening in the Conditional Fields issue que #206343: Compatibility with Fieldgroup tabs

dornea.nu’s picture

I've installed the dev version and the problem still occurs. I got a htab item field and a nodereference field which can be empty. In that case the htab field shouldn't be displayed.

michaek’s picture

Did this ever make it into a 1.x release? It doesn't seem like it.

michaek’s picture

I've been looking at field_group_remove_empty_display_groups in the current 7.x-1.x-dev, and it seems that one reason there could be ongoing issues is that testing for an empty array is not a reliable way to know if the array is going to render to an empty string. The fact that there's no good way to test whether something's going to render to an empty string without actually rendering it suggests that trying to null out empty children in advance might just be the wrong strategy.

Wouldn't it be simpler to do this in the render step? We could, I believe, use a custom render type (rather than markup) and return an empty string if there's no child output rendered.

tchopshop’s picture

I'm having this issue with the 7.x-2.x-dev version.

Is it fixed in the 7.x-1.x-dev version? Is it safe to back port or will I lose all my field sets?

This is a big problem, and for some reason I can't seem to make the javascript in #46 work, which would have been an ok work around for now.

I'm also using Display Suite, if that matters.

kenorb’s picture

If you're looking for some integration with Conditional Fields, see: #1161314: Fieldgroup support

deanw’s picture

Upgrading from Drupal 7.14 to Drupal 7.15 fixed this for me.

citkane’s picture

Great work-around at #46. Needs some modification for context. This worked or me:

Aaronwa’s picture

Drupal 7.16

#58 worked for me. Just put it in the global js file used by the site. Thanks

Nick Robillard’s picture

In my case I have field collection fields inside accordion items which are inside an accordion group, so my JS to hide empty accordion headers is the following. Hopefully this helps someone else.
$('.field-group-format-wrapper .field-items:empty').parents('.field-group-format-wrapper').prev('h3').hide();

Ndesign’s picture

This still shows my empty tabs if using a product reference on drupal commerce. It renders a empty horizontal tab being called out from my product variations.

pslcbs’s picture

Issue summary: View changes

Didn't get any patch working with 7.x-1.3 or 7.x-1.x-dev then I tried with jQuery

As #46 didn't work for me because my field group is not empty (it has an H2 label) I found this solution to check if fields are inside field group.

I'm using Display Suite too

Settings for field group:

  • div: open
  • classes: field-group-div
  • show_label: Yes
  • label_element: Header 2
  • effect: None
  • speed: Fast
jQuery(document).ready(function($) {

Hope this helps.

fonsv@ndamme.be’s picture

#62 Works perfectly, thanks!

ronaldmulero’s picture

Thanks pslcbs!
#62 does the trick for now!

For others still looking to implement this workaround, just add the following to your template.php. Note: You gotta replace "field-group-div" with the class of the fieldset you want to conditionally hide and "field" with the class of the field you want to check:

drupal_add_js('jQuery(document).ready(function($) { $(".field-group-div").not(":has(.field)").remove(); });', 'inline');

Drupal 7.31
Field Group 7.x-1.4
Conditional Fields 7.x-3.0-alpha1

eigentor’s picture

If somebody uses Tabs like horizontal tabs, you gotta do it a bit differently. I had the case and check if the fieldset has Field-items inside it. If so, I can run a function. Other than the .not() function this makes it possible to hide other elements than the fieldset or another direct parent of the .field or .field-items element. Like so:

// Check if there is a div.field-items inside .group-pd-tab-1
if ( $(".field-items").parents(".group-pd-tab-1").length == 0 ) {
  // If not (lenght == 0), run arbitrary commands or functions.
  // in this case, remove li.horizontal-tab-button-0

Of course this has to be inside a drupal_add_js or better in your custom .js file.

shaisamuel’s picture

Please help !!!

I am trying to hide empty fieldset around edit fields (in edit mode). I did try the bellow code (in template.php), but it doesn't work, even when the markup exits:

drupal_add_js('jQuery(document).ready(function($) { $(".field-group-div").not(":has(.field)").remove(); });', 'inline');

Any idea???

dreamer777’s picture

eigentor, thank you for solution. Is there any more general code that checks all the tabs?

Thank you for help!

jcaprio_nwe’s picture

the issue seems to be that, when you have a nested field group, even if all fields within the main field group and the nested are hidden, the main field group still displays, blank...

Seems like the main field group is treating the nested one like a "field" and because we cannot hide the nested field group itself, it shows an empty container for the main group.

Make sense and do we have a solution?