Making other elements conditional upon the selected transition

Created on 14 October 2022, about 2 years ago
Updated 16 February 2023, over 1 year ago

Problem/Motivation

When you try to make a conditional field (eg: display an input) based on currently selected transition the field doesn't appear. This is bacouse the webform use the input name in the condition and in the rendered form this name is duplicated.

Condition in the source YML:

 '#states':
    visible:
      ':input[name="workflow[transition]"]':
        value: switch

Where the "workflow" is the key for the workflow element.

Rendered Form:

<input data-drupal-selector="edit-workflow-transition" type="hidden" name="workflow[transition]" value="">

and

<select class="workflow-transition form-select" data-drupal-selector="edit-workflow-transition" aria-describedby="edit-workflow-transition--2--description" id="edit-workflow-transition--2" name="workflow[transition]"><option value="" selected="selected">- select transition -</option><option value="switch">Switch</option><option value="switch_2">Switch 2</option></select>

The hidden input stores the last saved transition in the value and the the select is the currently selected transition. If you make your condition in webform way, and refers to the field with the name attribute the hidden value will brake this condition.

Steps to reproduce

1) Make a workflow with at least 1 transition.
2) Select this workflow in the "Webform workflows element".
3) Create a new field with the condition above and set the value to your transition.
4) In the form select the transition and nothing happens

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇭🇺Hungary gabor.szabolcs

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • There are two issues with conditions in the current dev/beta:

    • The one above, which is making another element conditional upon the selected transition
    • The available conditions on the workflow element to make a transition conditional upon another element

    I've clarified the title of this one and will create an issue for the second one.

Production build 0.71.5 2024