You are here

function hook_conditional_fields_effects_alter in Conditional Fields 7.3

Alter the list of visual effects available to states.

Visual effects may provide settings that are passed to the js object Drupal.settings.conditionalFields.effects and that are automatically made available to the corresponding state change event under event.effect.

Dependent field events associated with effects have the effect name appended to the name, separated by a hypen; effect options are passed into the event argument. E.g.:

$(document).bind('state:STATE_NAME-EFFECT_NAME', function(e) { if (e.trigger) { // Effect options are stored in e.effect... } });

Parameters

$effects: An associative array of effects. Each key is the unique name of the effect. The value is an associative array:

  • label: The human readable name of the effect.
  • states: The states that can be associated with this effect.
  • options: An associative array of effect options names, field types, descriptions and default values.
1 invocation of hook_conditional_fields_effects_alter()
conditional_fields_effects in ./conditional_fields.module
Builds a list of supported effects that may be applied to a dependent field when it changes from visible to invisible and viceversa. The effects may have options that will be passed as Javascript settings and used by conditional_fields.js.

File

./conditional_fields.api.php, line 73
Hooks provided by Conditional Fields.

Code

function hook_conditional_fields_effects_alter(&$effects) {

  // Implement an effect for the addclass state.
  // The addclass event would be something like:
  // $(document).bind('state:addclass-toggleclass', function(e) {
  //  if (e.trigger) {
  //    $(e.target).toggleClass(e.effect.class, e.value);
  //  }
  // });
  $effects['toggleclass'] = array(
    'label' => t('CSS Class'),
    // This effect is associated with the following states.
    'states' => array(
      'addclass',
      '!addclass',
    ),
    // The values under options are form elements that will be inserted in
    // the dependency edit form. The key of this form element is also found in
    // the jQuery event argument under event.effect.class.
    'options' => array(
      'class' => array(
        '#type' => 'textfield',
        '#description' => t('One or more space separated classes that are toggled on the dependent.'),
        '#default_value' => '',
      ),
    ),
  );
}