Skip to main content

Posted this answer in the issue @attiks mentioned as well:

The easiest thing to do is to add the states in hook_form_alter() or in hook_form_FORM_ID_alter().

I got Clientside Validation to work on fields within a group, within a field collection.

Here's my code:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function fgtest_form_article_node_form_alter(&$form, $form_state) {
  $group = 'group_customgroup';
  $collection_bundle = 'field_my_collection';
  $fields = array_keys($form[$collection_bundle]['und'][0]['#group_children'], $group);
  foreach (element_children($form[$collection_bundle]['und']) as $delta) {
    $collection = &$form[$collection_bundle]['und'][$delta];
    foreach ($fields as $field) {
      $collection[$field]['und'][0]['value']['#states'] = array(
        'required' => array(
          "#edit-field-my-collection-und-{$delta}-field-make-required-und" => array('checked' => TRUE),
        ),
      );
    }
  }
}

And here's my setup:

Node Article:

snap1

Field Collection field_my_collection:

snap2

(Sorry, apparently I need 10 reputation to post images...)

Jelle
  • 473
  • 2
  • 7