0

I am trying to make field_format visible after two select list fields have a specific values selected. I thought be not using 'or' 'xor' that both are required but its not working. this is doing the same thing as using 'or',

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'page_node_form') {
    $form['field_format']['#states'] = array(
      'visible' => array(
          array(':input[name="field_item_type[und]"]' => array('value' =>     'tv_show')),
          array(':input[name="field_extra[und]"]' => array('value' =>     'bike')),
      ),
    );
  }
}
1
  • Did you want it to work like an xor or an or? Commented Mar 6, 2017 at 0:59

1 Answer 1

1

Here is some example code. Maybe your selector is incorrect?

$form['main']['elem1'] = array(
  '#type' => 'select',
  '#title' => t('1'),
  '#options' => drupal_map_assoc(array('A', 'B')),
);
$form['main']['elem2'] = array(
  '#type' => 'select',
  '#title' => t('2'),
  '#options' => drupal_map_assoc(array('A', 'B')),
);

$form['main']['elem3'] = array(
  '#type' => 'textfield',
  '#value' => t('3'),
  '#states' => array(
    'visible' => array(
      'xor',
      array(':input[name="elem1"]' => array('value' => 'A')),
      // XOR.
      array(':input[name="elem2"]' => array('value' => 'A')),
    ),
  ),
);
$form['main']['elem4'] = array(
  '#type' => 'textfield',
  '#value' => t('4'),
);
$form['main']['elem5'] = array(
  '#type' => 'textfield',
  '#value' => t('5'),
  '#states' => array(
    'visible' => array(
      ':input[name="elem1"]' => array('value' => 'A'),
      ':input[name="elem2"]' => array('value' => 'A'),
    ),
  ),
);

And then the alter function.

function module_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'af_aam_aam_form') {
    $form['main']['elem4']['#states'] = array(
      'visible' => array(
        array(':input[name="elem1"]' => array('value' => 'A')),
        // OR.
        array(':input[name="elem2"]' => array('value' => 'A')),
      ),
    );
  }
}

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.