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
  • Its working , Thanks Commented Dec 15, 2021 at 12:42
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 you have read our privacy policy.

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