Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently the #states
API has some support for some level of nesting with conditionals. It would be great if the webform UI supported creating and editing these nested conditionals.
Proposed resolution
- Investigate the current status of conditionals in the
#states
API. - Look at ways of representing this in the UI.
Comment | File | Size | Author |
---|---|---|---|
#12 | 2984995-12.patch | 14.93 KB | jrockowitz |
| |||
#10 | 2984995-8.patch | 16.36 KB | jrockowitz |
| |||
#3 | Screen Shot 2018-07-11 at 6.32.21 AM.png | 110.07 KB | jrockowitz |
#3 | Screen Shot 2018-07-11 at 6.28.20 AM.png | 166.58 KB | jrockowitz |
#3 | Screen Shot 2018-07-11 at 6.22.57 AM.png | 64.22 KB | jrockowitz |
Comments
Comment #2
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedWe are working with some complex conditionals that require nesting. Editing the yaml has been a great way to get these going fast but it has required some level of technical expertise.
Similarly, I've found it really hard to understand the scope of what is supported in
#states
in terms of:We also have scenarios that require "or" conditions at the level 1 depth. If we take some conditions like:
We've managed to expand these conditions out into the following, in order to work within the constraints of what is offered by the states API:
I wonder if the webform UI could support both "and" conditions and "or" conditions at both levels of depth, and then use some technique of expansion to transform them into a set of conditions that states supports.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe \Drupal\webform\WebformSubmissionConditionsValidator would also have to be updated to support nested conditions. This is a major undertaking which I personally don't have the resources or mental capacity to pursue.
We might consider copying the Views UI but I find Views nested filters confusing. The Conditional Fields module UI is using multi-step process and it is a little overwhelming.
I have to give @quicksketch credit for building a reasonable UI for complex use cases in the Webform module for D7.
I have a hard time wrapping my head around processing nested conditions and then building a sensible UI is even more challenging. A lot of form builders on the market have avoided supporting nested conditions.
Finally, I think Drupal core might need to update #states API and provide some sort of server-side validation to admin forms, especially if Form API starts supporting React base form.
A very reasonable MVP would be to update WebformSubmissionConditionsValidator to support nested conditions and continue to use YAML for writing advanced #states. There should be enough existing test coverage to prevent regressions while improving WebformSubmissionConditionsValidator.
Comment #4
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThank you for the analysis!
Adding a related issue which was the sub-conditionals issue which introduced similar nested functionality to D7, might help provide some point of reference for the kind of effort it takes to add such a UI to an existing non-nested UI.
I agree that additions to the UI would need to be done in such a way that were easy to maintain and didn't significantly increase the complexity and maintenance burden of the existing UI.
Good point, I've spun this off into #2985910: Extend support for nested conditionals in WebformSubmissionConditionsValidator.. I agree this would be a good step to take towards first class nested support, that would be decoupled from building any kind of UI.
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedTo begin to wrap my head around this issue I just wanted to post some YAML that illustrates a nested #states conditional (via a_and_b_or_c)
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI really don't want to support nested conditionals via the UI because the UX becomes too complex. For an element's #states advanced users can edit the YAML source. The only problem is that a handler's conditional logic's YAML can't be edited.
I am tempted to add an Ajax button link to switch on the ability to edit a #states YAML source.
Comment #9
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached patch adds an 'Edit source' button to the 'Conditional logic' builder. I will follow up with a change record.
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #11
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedHere is the change record.
Comment #12
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedSome minor cleanup.
Comment #14
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed the patch. Please download the latest dev release to review.