Conditional logic not handling pristine fields correctly

Created on 13 July 2023, over 1 year ago

Problem

Conditional logic can trigger incorrectly on pristine fields (that were not focused by the user), making some conditional logic render incorrectly.

Steps to reproduce

  1. Go to Simplytest.me and create a webform 6.1.4 sandbox.
  2. Login to the admin account (username: admin, password: admin) and import the attached webform ( webform.webform.conditional_logic.yml).
  3. View the webform and fill like below, without touching any empty field (especially not the married name field).
  4. Notice here how the married name field is considered "filled" when it should be "empty", causing display_name_ifall to be displayed instead of display_name_ifalias.

Result

The following picture shows that the last displayed field will be display_name_ifall instead of display_name_ifalias:

Expected Result

When entering anything in the married name field, then emptying it again, we can display the intended field, display_name_ifalias:

Proposed resolution

I do not know what causes this issue, but webform should handle pristine fields the same way it handles normal fields in this case.

I also do not know if this is an intended way of handling dynamic options in webform -- if there is another way that works the way I want it to, I'd be glad to know about it!

๐Ÿ› Bug report
Status

Active

Version

6.1

Component

Code

Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance maxime-adagp Paris, France ๐Ÿ‡ซ๐Ÿ‡ท

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

Comments & Activities

  • Issue created by @maxime-adagp
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    537 pass
  • ๐Ÿ‡จ๐Ÿ‡ดColombia Ozle Bogotรก

    Hey @maxime-adagp,

    Seems more like a problem with drupal.state library, in some cases the values โ€‹โ€‹of empty states appear as null and not booleans, so I created a patch from webform v6.1.x to make sure that the expected value is returned.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia kasli_harshit

    applied the #2patch , changes working as expected now ( Attcahed the snapshot for the same) the display_name_ifalias field is working as expected when the married name field is empty.

  • Status changed to Postponed: needs info over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jrockowitz Brooklyn, NY

    The example is so complex I can't determine what is going on. Please provide a simplified example. See attached for my attempt at a simplified example.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance maxime-adagp Paris, France ๐Ÿ‡ซ๐Ÿ‡ท

    Sorry if the example was too complex. I wanted to show my complete use case so that someone could point out whether there was a more idiomatic way of doing what I was trying to do (I was thinking variants but in the end it didn't work quite right).

    Attached is a more generic version, which I hope is simpler to understand.

    The crux of my issue is the fact that the state of a "pristine" text field -- that is to say, a text field that has not received input -- is filled. This should not be the case, because the text field is obviously empty at that point.

    This behavior is showcased in this new screenshot from the simplified version :

    The patch provided in #2 does seem to solve my issue, so I'll mark this RTBC.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jrockowitz Brooklyn, NY

    The patch might solve your problem but it is not clear if won't cause regressions.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nikhil_110

    #2 Patch applied, changes working as expected. I checked it in 4 steps which are as follows.

    1. The text field value will be filled and the check box will also be checked.
    2. The text field value will be empty and the check box will be checked.
    3. The text field value will be filled and the check box will be unchecked.
    4. Both fields will be empty and checked

    All test scenarios are working fine, I have also added screenshots, please check.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jrockowitz Brooklyn, NY

    I can replicate the issue with your example.

    The patch seems like a workaround to a core issue that should be addressed directly in states.js.

    For example, the patch changes code that we meant to be a work-around for IE11, which is no longer supported.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jrockowitz Brooklyn, NY

    We should explore removing the IE11 workaround.

    @see https://git.drupalcode.org/project/webform/-/blob/6.3.x/js/webform.state...

Production build 0.71.5 2024