1

I have a complex scenario in Webforms, where field #states depends on multiple OR / AND conditional logic.

For Example:

field_d has a visibility condition where field_a must be filled and either of field_b or field_c must be filled. I am not sure how to proceed with that kind of Yaml logic. I have tried something like below but it seems not to work.

field_d has below conditional logic under field advance tab -

visible:

  ':input[name="field_a"]':
      filled: true

  and

  (
  ':input[name="field_b"]':
      filled: true

  or

  ':input[name="field_c"]':
      filled: true
  )

Thanks.

2

Nested states can be tricky. Make it two conditions:

visible:
  - ':input[name="field_a"]':
      filled: true
    ':input[name="field_b"]':
      filled: true
  - or
  - ':input[name="field_a"]':
      filled: true
    ':input[name="field_c"]':
      filled: true
3
  • Hi @leymannx, yes it is working fine in that way. But in general any reference for nested conditions? It may not be feasible to use different conditions for all cases OR this is the preferred way to handle nested states?
    – Amit
    Apr 22 at 11:31
  • @Amit – I was at the same point once looking for nested Webform states documentation and all I found was drupal.org/project/webform/issues/2985910 and maybe some clues in the Webform code itself. So this is the way to go. Alternatively of course you can hook into the form yourself from a custom module and try your luck from the PHP side of the code. Webform Yaml at some points is just an abstraction layer on top of Drupal's Form API and not all what might be possible from PHP also works in Yaml.
    – leymannx
    Apr 22 at 12:51
  • Thanks for explaining it but of course PHP custom webform validation is not an option, I can take as there are 150+ complex webforms and moreover business wants a control to create Form conditionals by their own (Including the complex nested logics as well). In D7 that was the possibility through UI via "Webfom validation" module but in D8 falling back to YAML approach to achieve it.
    – Amit
    Apr 22 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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