Problem/Motivation
When setting the conditional on a webform field, nested states are giving an error.
Steps to reproduce
Create a conditional webform field, the webform field definition which breaks is:
assistant_dean_approval:
'#type': fieldset
'#title': 'Assistant Dean Approval'
'#states':
visible:
-
- ':input[name="assistant_dean_email"]':
value: '[current-user:mail]'
- or
-
- ':input[name="area_of_access"]':
value: some_area
- and
- ':input[name="current_logged_in_user"]':
value: some_user
Adding this on the Build|Source tab and saving does not give an error, but if I attempt to edit the element on the Build|Elements tab, ajax fails and the field dialog is not displayed. Looking into the logs, the error given is:
TypeError: Drupal\webform\Element\WebformElementStates::getStatesArrayCondition(): Argument #2 ($condition) must be of type array, string given, called in /opt/drupal/web/modules/contrib/webform/src/Element/WebformElementStates.php on line 795 in Drupal\webform\Element\WebformElementStates::getStatesArrayCondition() (line 815 of /opt/drupal/web/modules/contrib/webform/src/Element/WebformElementStates.php).
If I remove the nested '- and' condition, then there is no error and the element can be edited on the Build|Elements tab, but it does not behave as desired.
Note: https://www.drupal.org/docs/drupal-apis/form-api/conditional-form-fields... indicates that this type of nesting should be valid.
Proposed resolution
modify webform/src/Element/WebformElementStates.php to properly handle nested conditions.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork webform-3408243
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jrockowitz commentedDid you try to remove the 'and' and use...
Comment #3
kwfinken commentedThank you for the prompt response:
I have tried these variations, they save and edit without problem, but do not function properly.
and
For others facing the same problem, I did get things working properly by using a hidden computed twig field and then referencing that as the condition. So my problem is solved, but the fact that this is not working is not solved.
The way that worked is:
Comment #6
abhishek_gupta1 commented@kwfinken, I've incorporated updates addressing your concern. Please review the attached patch file for the modifications.
Comment #7
cilefen commentedComment #8
jrockowitz commentedComment #9
jrockowitz commentedThere is support for nested conditions with test coverage
@see https://git.drupalcode.org/project/webform/-/blob/6.3.x/tests/modules/we...
I was not able to replicate the original issue which has a workaround.
I don't see other people running into this issue.