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.

Comments

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:
http://drupal.org/sandbox/peem/1073388

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

sub

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.

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)

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

Yep, after update it's back again.

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.

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....

subscribe

Status:Needs review» Needs work

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

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.

Status:Needs work» Needs review

pushed and ready for testing. (in git repository)

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

Title:Fieldset displayed even if emptyFieldset 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

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.

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

HTgroup
-HTab
--LongTextField
-HTab
--LongTextField
..

----

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.

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

StatusFileSize
new16.75 KB
new13.94 KB

Screenshots to show my simple use case

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.

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.

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

I still have no problems at all. Somebody else?

StatusFileSize
new8.15 KB
new5.95 KB
new13 KB
new5.56 KB
new76.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.

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']); ?>
   </div>
<?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?

StatusFileSize
new439 bytes

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)

StatusFileSize
new71.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.

StatusFileSize
new27.87 KB

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 ;)

#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.

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

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.

Title:Fieldset displayed even if emptyFieldset displayed even if there is no content

change title

StatusFileSize
new1.13 KB

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.

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

#33 Nice, this works great! Thanks.

#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.

Ok
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.

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

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.

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

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

Status:Needs review» Fixed

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

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.

Sry for the undefined function :)

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

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

http://drupalcode.org/project/field_group.git/blobdiff/0d4abd2e2ebe7e9fa...

If I undo this commit my field groups re-appear

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.

jQuery(document).ready(function($){
    $(".field-group-format:empty").remove();
});

Status:Fixed» Closed (fixed)

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

Status:Closed (fixed)» Active
StatusFileSize
new1.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.

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.

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

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

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.

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

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.

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.

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

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

Great work-around at #46. Needs some modification for context. This worked or me:
$(".fieldset-wrapper:empty").parent().remove();

Drupal 7.16

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

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();

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.