I would like to be able to show/hide a group of fields (according to the documentation it's supposed to work).

I've created a fieldset with all fields that will be dependent but this group field is not in the list of dependent. How can a dependee affect a group of dependent fields ?

Thanks!

Comments

Title:Fieldgroup do not appear in the list of dependentFieldgroup support
Component:User interface» Compatibility w/ other modules
Category:bug» feature

This functionality is still missing from Conditional Fields 7.x-3.x. Please follow this issue for announcements when it will be implemented.

subscribe

subscribe

Subbing

Subbing too.

+1

subscribe

Assigned:Unassigned» thomasvum

subscribe

I don't think you meant to assign it to you - unless you intend to fix this yourself?

No, you are right, but can't change it back.

Assigned:thomasvum» Unassigned

That's because I fixed it for you :)

subscribe

I was taking a shot at implementing this and found that under current implementation this seems almost impossible. The conditional_fields table saves only the field id, which is a number. Based on this number there is no way of knowing whether it is a regular field or a group field.

What I think is that in order to implement this the conditional_fields table should change to store the field name instead. Or add another column that specifies if this is a field or a group field.

What do you think?

Also, this only would apply to the dependent field, as no dependee can be a field group.

sub!!!

Subscribing;

+1 subscribing

subscribing

subscribe

subscribe

+1

this would be very useful.

Field group support is not a small task, it will probably take some time. In the meantime, consider using the Field collection module, which already works (almost) perfectly with Conditional fields.

#14: You're right, it would be necessary to change the schema by adding a 'dependent_type' or 'dependent_module' column that identifies the type of dependent (field or fieldgroup).

Wow! I didn't know about field_collection. But looks pretty nice. Hope to try it soon.

subscribe.
Field collection it's a good tool, but why should we build new entities when just some grouped fields are needed.
I think this is a very needed feature and more than nice to have.

+1

sub

sub

+1 For this.

@davidlerin there is now a follow button at the top you know =)

This feature would be great!

I have a huge form with 100+ fields that are dependent on each other and I would really like to display them using tabs split into their categories etc rather than on one massive long page as not all fields are needed depending on the initial selection.

I found that Conditional Fields module does actually work with Fieldgroup module. I use vertical tabs for sorting all my fields. Unless both dependent and dependee are in the same tab, dependencies work.

@Rontero - what do you mean 'it works'? Im using Accordion groups to group fields, and these accordion groups not available for selection by conditional fields. Accordian are much the same as vertical tabs in terms of the implementation - it's just a different widget on the fieldgroup. How exactly re you using vertical tabs with conditional fields?

@mrfelton I'm using conditions on fields not on accordions etc. As long as yoour dependent and dependee are in the same group, Conditional Fields module works.

Example from my site:

I have Drupla Commerce installed for adding products to my site.
Case: Select the appropriate country (the manufacturer is based in) after user selects maker's name.

  1. Product group called basic info (type: vertical tab)
    • Field 1: Maker's name (field type: select list)
    • Field 2: Maker's country (field type: select list)

First field is dependee and second is dependent.

After constructing such a form, in manage dependencies tab i made proper dependent/dependee selections and as a rule used fields with a value / has value.

I hope this helps.

@Rontero;

True, even if the two fields are not in the same field group the dependencies work. For example, one client's site has registrants choose individual or group registration type. If they choose individual several conditional fields will be shown and vice versa if you choose group.

But what he wants and what I'm trying to get working again is that the entire field group will be shown or hidden pending the choice. Otherwise even if I set each field to show or hide pending the choice, the field group still shows - with the label for it - just none of the individual fields do.

I'm looking for the same solution as Fanaile

@Fanaile: This is exactly what I am in need of, too. Please let us know in case you solve this in any way.

Yes, getting the

entire field group will be shown or hidden pending the choice

would be a great feature that's needed.

In D7: It would be better to use a parent/child situation. A new field that is the field id of the field_group table as the parent_id. start gathering the children and see if they all have the same parent. if so then show the parent.

Very interested too, has there been any movement on this or will there even be any attempt to implement the feature?

Oh, no activity here ;(

sub

Any way to display or not an entire group using CF?

+1 subscribing

For now you can kinda do this with javascript. We haven't tested this too much, but have it running on one of our sites.

First, make a javascript/jquery function to hide empty fieldsets

Drupal.mymodule.cleanupFieldsets = function() {
    $("fieldset").each(function(){
      var fieldset = $(this);
      fieldset.show();
      var wrapper = fieldset.find(".fieldset-wrapper");
      if(wrapper.height() == 0){
        fieldset.hide();
      }
      else{
        fieldset.show();
      }
    });
  }

Then, bind a change event to every form widget in your node form to fire the cleanup function

  $('input, select').change(function(){
    Drupal.mymodule.cleanupFieldsets();
  });

+1

subscribing

subscribe

i test "field collection" and "fields group" modules with conditional field on profile 2.
but not works

Please support fieldset feature.

@Fanaile #34:

For example, one client's site has registrants choose individual or group registration type. If they choose individual several conditional fields will be shown and vice versa if you choose group.
But what he wants and what I'm trying to get working again is that the entire field group will be shown or hidden pending the choice. Otherwise even if I set each field to show or hide pending the choice, the field group still shows - with the label for it (---)

I have just tested these modules together
Conditional Fields 7.x-3.x-dev
Field collection 7.x-1.0-beta5

in purpose to see if it solves the issue mentioned in this thread with still showing labels for fieldgroups with hidden fields.
And as far I can see from my test, it works!
I did try with fields at admin/config/people/accounts/fields

And since then?

Would it not be better to have conditions for field groups?
Then you can show/hide entire field groups and its fields with 1 simple field condition.

If the field has value then show field group

Maybe this will have to be an add-on module

EDIT:

Wait, I want to hide an empty fieldset if the fields in the fieldset are not visable due to the field condition.

hey folks, if you want to show/hide a whole fieldgroup conditionally:

you have to use the hook_field_group_build_pre_render_alter()

Simply :

function your_module_field_group_build_pre_render_alter(&$element) {
  $element['your_field_group']['#states'] = array(
    'visible' => array(
      ':input[name="field_checkbox"]' => array('checked' => TRUE),
    ),
  );
}

This works perfecly. If the group A is in an another group, do this

$element['groupA']['groupB']['#states'] etc....

Courtesy of bobylapointe over at stackpoint.

Works well.

Perhaps conditional fields would implement it as such.

This code didn't work for me. Also I receive this message:

Notice: Undefined index: #id in drupal_process_states() (line 4664 of /Users/me/Sites/tests/includes/common.inc).

I finally got this working - similar to #51 & http://drupal.stackexchange.com/questions/14635/hide-a-cck-fieldgroup-us... (but with added if statement to prevent errors I was getting with other modules.

function your_module_field_group_build_pre_render_alter(& $element) {
  if (isset($element['your_field_group'])){
$element['your_field_group']['#states'] = array(
'visible' => array(
'#edit-field-name-und' => array('checked' => TRUE),
)
);
}
}

Issue summary:View changes

Before I try this code, just a stupid question.

Does this code show/hide the fieldgroup using JavaScript in real-time or only after a node save?

And settings like speed and fade options would be a bit more complicated I guess.

Does this code show/hide the fieldgroup using JavaScript in real-time or only after a node save?

And settings like speed and fade options would be a bit more complicated I guess.

This shows/hides in real time, but doesn't use javascript, though I'm sure it could be done... perhaps look at: https://drupal.org/node/304255 or http://drupal.stackexchange.com/questions/6960/how-to-add-jquery-plugin-...

+1 subscribing

I'm willing to pay for development of this functionality. Send me a note if interested.

Thanks.

Here is one workaround for this problem that might help someone. I just tested and it worked.

As stated above conditional fields module supports field collections created by Field Collection module, but not field groups created by Field Group module.

Instead of adding field group with a bunch of fields directly to the content type you can add it to a field collection. Then you can apply conditions to that field collection and control visibility of all the field groups and fields inside this field collection.

@gd1008, moving fields from a field group to a field collection does not work if you are using Display Suite for node display. The conditional aspect of the node edit form works fine. The field collection doesn't display in the node view. Have looked at Display Suite and Conditional fields for a solution - none. I don't know where it's easier to address: Field Group, Field Collection, Conditional Fields, or Display Suite. It's a convoluted and interesting interplay between the modules.

I tried to apply the #51 and #53 patches, but without success.
Can someone confirm that they work and how?

These aren't patches, but are meant to be used as a custom module. It's really a work around, but yes it does work just fine.

You should be able to paste the code into "your_module.module". Next rename the field_group and field_name parts to match your actual fields. Then just create "your_module.info", put it all in a folder in your modules directory and enable it.

Either use the code from #51 or #53 (not both).

#44 does not work for the case of horizontal or vertical tabs. If you want to hide a tab instead of a field group, use this Javascript snippet:

(function($){
  var cleanupFieldsets = function() {
    $("fieldset").each(function(){
      var fieldset = $(this);
      // Find out if the fieldset contains only elements that are hidden,
      // regardless of the fieldset itself being hidden.
      var countShownSubFields = 0;
      $(fieldset).find('div.form-wrapper').each(function(){
        if ($(this).css('display') === 'block'){
          countShownSubFields++;
        }
      });
      var data = fieldset.data();
      // Horizontal tab support
      if (data && data.horizontalTab) {
        if (countShownSubFields === 0) {
          fieldset.data('horizontalTab').item.hide();
        } else {
          fieldset.data('horizontalTab').item.show();
        }
      }
      // Vertical tab support
      if (data && data.verticalTab) {
        if (countShownSubFields === 0) {
          fieldset.data('verticalTab').item.hide();
        } else {
          fieldset.data('verticalTab').item.show();
        }
      }
    });
  }
  $(document).ready(function(){
    cleanupFieldsets();
    $('input, select').change(cleanupFieldsets);
  });
})(jQuery);