Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

How to use #states in add node form? I don't experience any problems when use them with exposed filters (on user side), but cannot do the same when additing new nodes. I tried the following code:

function custom_module_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'article_node_form') {
    $form['field_coordinate']['und'][0]['#default_value'] = t('1');
    $form['field_name_tag']['und']['0']['#states'] = array(
      'invisible' => array('select[id="edit-field-location-tag-und"]' => array('value' => '1')),
    ); 
  };
}

Where is my mistake?

share|improve this question
1  
the semicolon ; after the if block? –  AjitS Nov 22 '12 at 7:11
    
not, it didn't help –  moto Nov 22 '12 at 7:26
    
try using 'invisible' => array(':select[id="edit-field-location-tag-und"]' => array('value' => '1')) ;note the : before select –  AjitS Nov 22 '12 at 7:37
add comment

1 Answer

The #states array has the following structure.

array(
  STATE1 => CONDITIONS_ARRAY1,
  STATE2 => CONDITIONS_ARRAY2,
  // ...
)

The condition array has the following structure.

array(
  JQUERY_SELECTOR1 => REMOTE_CONDITIONS1,
  JQUERY_SELECTOR2 => REMOTE_CONDITIONS2,
  // ...
)

JQUERY_SELECTOR is a selector that is valid in jQuery, such as :input[name="foo"].

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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