문제

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!

도움이 되었습니까?

해결책

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'),
        ),
    ),
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top