WebformElementStates::buildConditionRow() has faulty code

Created on 6 August 2024, about 1 year ago

Problem/Motivation

In WebformElementStates::buildConditionRow() there is code to add a row to the conditions table. It includes this code:

    $row['condition']['pattern'] = [
      '#type' => 'container',
      'description' => ['#markup' => t('Enter a <a href=":href">regular expression</a>', [':href' => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions'])],
      '#states' => [
        'visible' => [
          [$trigger_selector => ['value' => 'pattern']],
          'or',
          [$trigger_selector => ['value' => '!pattern']],
        ],
      ],
    ];

    $row['condition']['pattern'] = [
      '#type' => 'container',
      'description' => ['#markup' => t('Enter a number range (1:100)')],
      '#states' => [
        'visible' => [
          [$trigger_selector => ['value' => 'between']],
          'or',
          [$trigger_selector => ['value' => '!between']],
        ],
      ],
    ];

Because the two arrays have the same variable name this results in the second one always overwriting the first value.

Looking at the annotations for the file, the second variable was added in #3108564: Add support for between #state. β†’ .

Proposed resolution

Rename the second 'pattern' section, update associated logic so that the field for the "pattern" string is different to the field for the "between" string.

Remaining tasks

Make the fixes.
Update test coverage.

User interface changes

A different field will be shown if someone selects the "pattern"/"not pattern" condition versus the "between"/"not between" condition.

API changes

n/a

Data model changes

n/a

πŸ› Bug report
Status

Active

Version

6.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024