0

When the order of calling the implementation of a particular hook by different modules matter, you can change the weight of modules by tweaking system database table.

But it looks like I'm in a more difficult situation involving interaction of the field_group, and the clientside_validation modules with my custom module.

I use hook_field_group_build_pre_render_alter() provided by the field_group module to add some '#states' attributes to a field group form element.

The states I add change the '#required' attribute, besides other things. This form relies on a clientside_validation module suite to provide a JavaScript validation.

There is a brand-new module, clientside_validation_states which perfectly fits me, but I ran into the difficulties trying to make use of it. clientside_validation_states uses #after_build, which should be called after my code, but hook_field_group_build_pre_render_alter() is called in field_group by using a '#pre_render' FAPI attribute.

This together results in an inverted calling order. Do you have any idea on how to fix this?

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.