title: Conditional fieldgroups/fieldsets in Drupal 7
body: <p><strong>Background:</strong> In Drupal 7, I have created a form with CCK (aka the Field UI). I used the <a href="http://drupal.org/project/field_group">Field group</a> module to create a fieldgroup, but I need it to be conditional, meaning it will only display depending on a previous answer.</p>
  
  <p><strong>Previous research</strong>: To create a conditional field, you can use <a href="http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7">hook_form_alter()</a> to edit the <a href="http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#states">#states</a> attribute like so:</p>
  
  <pre><code>function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    if ($form_id == 'person_info_node_form') {
      // Display 'field_maiden_name' only if married
      $form['field_maiden_name']['#states'] = array(
        'visible' =&gt; array(
          ':input[name="field_married[und]"]' =&gt; array('value' =&gt; 'Yes'),
        ),
      );
    }
  }
  </code></pre>
  
  <p>However, there seems to be no way to use the States API for fieldgroups. One thing to note is that, while fields are stored in <code>$form</code>, fieldgroups are stored in <code>$form['#groups']</code> as well as in <code>$form['#fieldgroups']</code>. I don't know how to distinguish between these, and with this in mind, I have tried to apply a <a href="http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#states">#states</a> attribute to a fieldgroup in the same manner as above. However, it only produces server errors.</p>
  
  <p><strong>Question</strong>: Is there a way to make a fieldgroup display conditionally using the States API or some alternative approach?</p>