Prefix is shown before description

Created on 8 July 2024, 5 days ago
Updated 11 July 2024, 2 days ago

Problem/Motivation

When creating a number field and filling in a prefix and description where the 'Description display' is set to 'Before', the prefix will be shown before the description instead of the field.

This results in unwanted behaviour when, for example, you've set the prefix to a currency (such as € or $) and you want to display a description above the field. It will first show the currency symbol follow by the description and the input field. Instead you want to show the description first and the currency symbol right before the input field as it makes more sense.

Steps to reproduce

  1. Create a Webform with the Webform module.
  2. Create a 'Number' element.
  3. Fill in the description.
  4. Fill in the prefix.
  5. Set 'Description display' to 'Before'.
  6. Save the element and view the form.

Proposed resolution

Show prefix in front of field instead of in front of the description when 'Description display' is set to 'Before'.

This can be done by swapping lines 71-73 with 74-78 in the following file:
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/syste...

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Form 

Last updated about 18 hours ago

Created by

🇳🇱Netherlands rroose

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @rroose
  • 🇳🇱Netherlands rroose
  • Assigned to Sourav_Paul
  • Pipeline finished with Success
    5 days ago
    Total: 505s
    #218708
  • Issue was unassigned.
  • Status changed to Needs review 5 days ago
  • 🇮🇳India Sourav_Paul Kolkata

    Issue Fixed:

    SS:

  • 🇮🇳India Kanchan Bhogade

    I've Tested MR 8695 on Drupal 10.3.x-dev
    MR is applied Successfully...

    Testing steps:

    1. Create a Webform with the Webform module.
    2. Create a 'Number' element.
    3. Fill in the description.
    4. Fill in the prefix.
    5. Set 'Description display' to 'Before'.
    6. Save the element and view the form.

    The Prefix is shown before the Number field instead of before the description.

    Attaching SS for reference
    RTBC+1

    Keeping "Needs review" for Code verification

  • Status changed to Needs work 5 days ago
  • 🇺🇸United States smustgrave

    MR should be against 11.x branch.

    Also probably will need test coverage and definitely a change record.

    Recommend steps are updated using just core without a contrib to make sure the bug isn't from contrib.

  • Assigned to Sourav_Paul
  • Pipeline finished with Success
    3 days ago
    Total: 467s
    #220766
  • Pipeline finished with Success
    3 days ago
    Total: 492s
    #220768
  • Issue was unassigned.
  • Pipeline finished with Success
    3 days ago
    Total: 546s
    #220795
  • 🇮🇳India Akhil Babu Chengannur
    • web/core/profiles/demo_umami/themes/umami/templates/classy/form/form-element.html.twig
    • web/core/themes/stable9/templates/form/form-element.html.twig
    • web/core/themes/starterkit_theme/templates/form/form-element.html.twig

    All these core templates follow the same structure for prefix

      {% if prefix is not empty %}
        <span class="field-prefix">{{ prefix }}</span>
      {% endif %}
      {% if description_display == 'before' and description.content %}
        <div{{ description.attributes }}>
          {{ description.content }}
        </div>
      {% endif %}
    

    Shouldn't we update all of them. Or is it something that should be handled by the 'webform' module itself?

  • 🇳🇱Netherlands rroose

    I think we should. I see no valid reason or argument to put the prefix before the description, so it seems like a mistake or bug. The prefix is mostly used to indicate what value the user needs to enter, such as a currency.

Production build 0.69.0 2024