1

In mymodule_form_alter() I am programmatically setting states for my conditional fields. I.E.

$form['my_field_one']['#states'] = array(
              'visible' => array(
                ':input[name="my_dependee_field[und]"]' => array('value' => 'primary'),
              ),
            );

And this works great!

However, I need to assign some of my fields the OR functionality (multiple allowed dependee values) and can't quite figure out how to assign it programmatically (please excuse my limited experience with PHP).

I've tried some things such as...

$form['my_field_one']['#states'] = array(
  'visible' => array(
    ':input[name="my_dependee_field[und]"]' => array('value' => array('0' => 'primary','1' => 'secondary',),),
  ),
);

...with (obviously) no luck.

Can any kind soul lend a helping hand, or point me in the right direction. It is crucial that I accomplish this programmatically.

Any assistance is GREATLY appreciated.

THANKS!

MTsrb
  • 377
  • 1
  • 5
  • 11

1 Answers1

2

Update your #state using an array with two possible values:

$form['my_field_one']['#states'] = array(
    'visible' => array(
        ':input[name="my_dependee_field[und]"]' => array(
            array('value' => 'primary'),
            array('value' => 'secondary'),
        ),
    ),
);
Mike Vranckx
  • 5,557
  • 3
  • 25
  • 28
  • Thanks Mike! That worked perfectly with JQuery 1.5. Is there any reason you know of that would cause the JQuery on the page to break for JQuery 1.7 and 1.8, with this solution? – MTsrb Oct 18 '13 at 18:28
  • You're welcome! No idea, I always stay with the stock version jQuery on Drupal website. What do you have as javascript error? – Mike Vranckx Oct 18 '13 at 19:29
  • Yeah I'm using the Jquery Update module and it's up to 1.8, but with options of 1.7 and 1.5. I noticed the same issue even when using the Conditional Field module thru the UI (multiple dependee values only worked with JQuery 1.5). I'm actually not getting any errors, just that the admin bar is missing and none of the collapsible field groups function correctly. As well as all conditional fields I've set don't work. Very odd. – MTsrb Oct 18 '13 at 19:39