Hi,

what i try to to is this:

open a field if checkboxes A+B are checked. But it doesnt work via conditionals. Field appears when only one of the checkboxes is checked. But i set the condition that this should happens only when both are checked (see screenshots).

best,

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lolhonk created an issue. See original summary.

jrockowitz’s picture

Status: Active » Needs review
FileSize
1.26 KB

The attached patch adds the below example of multiple checkboxes being used as trigger to 'Example: Elements: Condition Logic' (form/example-elements-states)

checkboxes_example:
  '#type': details
  '#title': 'Checkboxes example'
  '#open': true
  checkboxes:
    '#type': checkboxes
    '#title': 'Please check all'
    '#options':
      one: One
      two: Two
  checkboxes_explain:
    '#type': textarea
    '#title': 'Please explain why you checked all the above box'
    '#states':
      visible:
        ':input[name="checkboxes[one]"]':
          checked: true
        ':input[name="checkboxes[two]"]':
          checked: true
      required:
        ':input[name="checkboxes[one]"]':
          checked: true
        ':input[name="checkboxes[two]"]':
          checked: true

  • jrockowitz committed cbe29a8 on 8.x-5.x
    Issue #2855258 by jrockowitz, lolhonk: conditionals with multiple...
jrockowitz’s picture

Status: Needs review » Closed (works as designed)

I committed the working example. Please checkout the latest dev release and review.

vgutekunst’s picture

youre crazy fast and good!

i checked it and i can confirm it works with element "textarea" but not with element "message".

here the yaml

checkboxes_example:
  '#type': details
  '#title': 'Checkboxes example'
  '#open': true
  checkboxes:
    '#type': checkboxes
    '#title': 'Please check all'
    '#options':
      one: One
      two: Two
  checkboxes_explain:
    '#type': textarea
    '#title': 'Please explain why you checked all the above box'
    '#states':
      visible:
        ':input[name="checkboxes[one]"]':
          checked: true
        ':input[name="checkboxes[two]"]':
          checked: true
      required:
        ':input[name="checkboxes[one]"]':
          checked: true
        ':input[name="checkboxes[two]"]':
          checked: true
  455:
    '#type': message
    '#states':
      visible:
        - ':input[name="checkboxes[one]"]':
            checked: true
        - ':input[name="checkboxes[two]"]':
            checked: true
      required:
        - ':input[name="checkboxes[one]"]':
            checked: true
        - ':input[name="checkboxes[two]"]':
            checked: true
    '#message_message': |
      <pre>
      <code>Message body

vgutekunst’s picture

FileSize
33.38 KB
vgutekunst’s picture

Status: Closed (works as designed) » Needs review
jrockowitz’s picture

I can duplicate the issue. The below code...

455:
    '#type': message
    '#states':
      visible:
        ':input[name="checkboxes[one]"]':
          checked: true
        ':input[name="checkboxes[two]"]':
          checked: true
    '#message_message': 'Message body'

...is being converted via the UI to...

455:
    '#type': message
    '#states':
      visible:
        - ':input[name="checkboxes[one]"]':
            checked: true
        - ':input[name="checkboxes[two]"]':
            checked: true
    '#message_message': 'Message body'

which is being interpreted as an 'or' instead of an 'and' operator.

jrockowitz’s picture

Status: Needs review » Needs work

The last submitted patch, 9: conditionals_with-2855258-9.patch, failed testing.

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
2.52 KB

  • jrockowitz committed b3c237e on 8.x-5.x
    Issue #2855258 by jrockowitz, lolhonk: conditionals with multiple...
jrockowitz’s picture

Status: Needs review » Fixed

Fixed. Pleas checkout or download the latest dev release.

vgutekunst’s picture

It works! Thank you very much jrockowitz!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.