5

In my form, there are 3 selection list A, B and C.

I wanna show or hide C based on values of A and B selected. C should be shown if A's value = 'all and B's value != 'all'

How to set the #state condition in this case?

 $form['C'] = array(
        '#type' => 'select',
        '#title' => t('C'),
        '#states' => array(
            'visible' => array(
                ':input[name="A"]' => array('value' => 'all'),
                ':input[name="B"]' => array('value' => 'all') //???how to set !='all' here?
            )
        )
)

2 Answers 2

6

This code should work:

':input[name="B"]' => array('!value' => 'all')
1
2

Although I don't think you can make negative condition with states in D7, you can make C invisible when B value equal all.

$form['C'] = array(
    ...
    '#states' => array(
       'visible' => array(
          ':input[name="A"]' => array('value' => 'all'),
       ),
       'invisible' => array(  // you choose 'invisible' parameter
          ':input[name="B"]' => array('value' => 'all')
       )    
    )
)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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