Very new to working with D7, worked on D6 for years though, and I'm trying life without conditional fields.

I'm trying to change a state of two groups of check boxes in the node form, and I can't get it to work.

I have two fields:

field_organization
field_administrative_division

I want 'field_administrative_division' to appear based on one of three values selected in 'field_organization'.

This is the code base I'm using in a custom module. I've used every variant I can think of from documentation and other suggestions, and I get zero results:

<?php
$form['field_administrative_division']['#states'] = array(
    'visible' => array(
      ':input[name="field_organization"]' => array('checked' => TRUE),
    ),
  );

I've read there could be some naming issues with the fields, but the field names are not quite so straightforward with things like 'field_organization[und][Administrative]' for the checkbox I'm wanting to trigger, and the field for division has similar names (field_administrative_division[und][1] for the first checkbox)

I've read all sorts of other ideas, and tried many, but nothing is working. I don't know if its syntax, something with checkboxes, or names. I am also wondering if it's just something simple like no initial condition being set.

Any help would be much appreciated.

Comments

Maybe have two solutions

If i did not misunderstand.
(1)go to the field edit form (eg:admin/structure/types/manage/YOURCONTENTTYPE/fields/YOURFIELD). In the 'Allowed values list' textarea, you can input 'KEY|VALUE' for you checkboxes.
(2)if (1) did not solve your problem, maybe you can just change the 'CSS selector', use 'id' instead 'name'.(eg: ':input[id="field_organization-und-Administrative"]' => array('checked' => TRUE),).
hope can help you.
Thanks

We need action!!!

I'm thinking there should be

I'm thinking there should be no colon (:) in front of 'input'. But maybe you know something I don't.

Jaypan We build websites

Thank you for the

Thank you for the suggestions, but I have tried all combinations of the above and nothing is working. The module is installed, and there's nothing else in there other than the script I posted, so I'm unsure what else it could be.

Also, I tried it with the colon and without, no results.

I fixed this with the help of

I fixed this with the help of IRC user danielbeeke:

Turns out I was using hook_form_alter improperly.

I used devel / dsm to get the form id.

drupal_set_message($form_id);

here's the result:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'profile_node_form') {
$form['field_administrative_division']['#states'] = array(
    'visible' => array(
      'input[name="field_organization[und][2]"]' => array('checked' => TRUE),
    ),
  );

}

This may be common sense to most, but I'll clarify in case someone else needs:

You can just inspect the form element itself to get the name of the dependee. You'll need to use the DOM name, not simply 'field_whatever', as with the form, since you're using javascript for the actual function piece.

nobody click here