Probable typo in Range element for "left" configuration

Created on 18 March 2024, 3 months ago
Updated 6 April 2024, 3 months ago

Problem/Motivation

Living example of how this issue impacts a "real" site: https://dev9.worldcampus.psu.edu/form/example-ranges

When configuring a Range element to Output the range's value to the Left AND there is not a prefix set on the range element itself, the output element is erroneously rendered as a field suffix!

This is the code in question:

https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Plugin/Webfo...

      if ($element['#output'] === 'left') {
        if (isset($element['#field_prefix'])) {
          $element['#field_prefix'] = [
            'output' => $output,
            'delimiter' => ['#markup' => '<span class="webform-range-output-delimiter"></span>'],
            'content' => (is_array($element['#field_prefix'])) ? $element['#field_prefix'] : ['#markup' => $element['#field_prefix']],
          ];
        }
        else {
          $element['#field_suffix'] = [  // <-- Shouldn't this be $element['#field_prefix'] instead?
            'output' => $output,
            'delimiter' => ['#markup' => '<span class="webform-range-output-delimiter"></span>'],
          ];
        }
      }

Steps to reproduce

See attached webform; note that the Range (value to left) element renders incorrectly.

Proposed resolution

Super simple! Let's change '#field_suffix' to '#field_prefix'!

User interface changes

If anyone has worked around this by using something like `flex-direction: row-reverse`, their hack-around will break.

API changes

None

Data model changes

None

πŸ› Bug report
Status

Needs review

Version

6.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Luke.Leber Pennsylvania

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

Merge Requests

Comments & Activities

  • Issue created by @Luke.Leber
  • Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update 3 months ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States Luke.Leber Pennsylvania
  • Pipeline finished with Failed
    3 months ago
    Total: 2596s
    #122731
  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States Luke.Leber Pennsylvania

    Seems HEAD was broken. Back to NR. πŸ‘

  • Status changed to Closed: works as designed 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    The delimiter can be displayed to elements left or right, which is why the #field_suffix is used.

  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States Luke.Leber Pennsylvania

    Hey Jacob,

    I may not have communicated things as clearly as intended, so I recorded a quick screencast that walks through what I found (~3 minutes). If I'm still not understanding correctly, please feel free to re-close and I won't re-open it again.

    Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States Luke.Leber Pennsylvania

    Problem/Motivation

    Living example of how this issue impacts a "real" site: https://dev9.worldcampus.psu.edu/form/example-ranges

    When configuring a Range element to Output the range's value to the Left AND there is not a prefix set on the range element itself, the output element is erroneously rendered as a field suffix!

    This is the code in question:

    https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Plugin/Webfo...

          if ($element['#output'] === 'left') {
            if (isset($element['#field_prefix'])) {
              $element['#field_prefix'] = [
                'output' => $output,
                'delimiter' => ['#markup' => '<span class="webform-range-output-delimiter"></span>'],
                'content' => (is_array($element['#field_prefix'])) ? $element['#field_prefix'] : ['#markup' => $element['#field_prefix']],
              ];
            }
            else {
              $element['#field_suffix'] = [  // <-- Shouldn't this be $element['#field_prefix'] instead?
                'output' => $output,
                'delimiter' => ['#markup' => '<span class="webform-range-output-delimiter"></span>'],
              ];
            }
          }
    

    Steps to reproduce

    See attached webform; note that the Range (value to left) element renders incorrectly.

    Proposed resolution

    Super simple! Let's change '#field_suffix' to '#field_prefix'!

    User interface changes

    If anyone has worked around this by using something like `flex-direction: row-reverse`, their hack-around will break.

    API changes

    None

    Data model changes

    None

Production build 0.69.0 2024