0

I try to hide a whole date/image/taxonomy block on my node form dependent on a checkbox. If use the following for my title field it works perfectly. The title field is hidden/visible dependant on the test_box checked value.

function interceptor_box_listener(&$form, &$form_state) {
  $form['test_box'] = array(
    '#title' => t('You want to choose a title?'),
    '#type' => 'checkbox',
  );
  $states_array = array(
    'visible' => array(
      'input[name="test_box"]' => array('checked' => TRUE),
    ),
  );
  $form['title']['#states'] = $states_array;
  return $form;
}

The point is that I have more complex fields I need to toggle and I'm not able to address them correctly. If I try to adress the following fielditem, nothing happens at all.

<div id="edit-field-plakat" class="field-type-image field-name-field-plakat field-widget-image-image form-wrapper">
<div id="edit-field-plakat-und-0-ajax-wrapper">
<div class="form-item form-type-managed-file form-item-field-plakat-und-0">
<label for="edit-field-plakat-und-0">Plakat</label>
<div class="image-widget form-managed-file clearfix"><input type="hidden" value="109" name="field_plakat[und][0][fid]">
</div></div></div></div></div>

It tried the following:

$form['field_plakat[und][0][fid]']['#states'] = $states_array;

Is there any possibility to just pass an id to drupal but stay with the states system? Of course I'd be able to use plain javascript here, but I really like to stay strictly on the module side.

1 Answer 1

1

Find this field in $form array and set states currently to it. I'm not sure, but maybe it is in $form['field_plakat'][LANGUAGE_NONE][0][$fid]? It must be somewhere in this renderable $form array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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