'Item' element with #states is not displayed in preview

Created on 15 November 2024, about 1 month ago

Problem/Motivation

The Webform element "Item" is not displayed in the preview step when #states visibility conditions are configured. "Item" has setting: display on "both form and viewed submission".

Steps to reproduce

  1. Use the webform.webform.test_item.yml Webform configuration for testing.
  2. In the first step, set a number value for the "Field number" field.
  3. Go to the Preview step, where the "Item title" element is not displayed as expected.

Proposed resolution

Unset #states in src/Plugin/WebformElement/Item.php to ensure the element displays correctly in the Preview.

πŸ› Bug report
Status

Active

Version

6.2

Component

Code

Created by

πŸ‡±πŸ‡ΉLithuania matask Vilnius

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

Comments & Activities

  • Issue created by @matask
  • πŸ‡±πŸ‡ΉLithuania matask Vilnius

    I am uploading the proposed solution with item-element-is-not-displayed.patch.

    In the WebformElement/Item.php class, the buildHtml method is rewritten to remove #states:

    public function buildHtml(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
      // Remove #states.
      unset($element['#states']);
    
      return parent::buildHtml($element, $webform_submission, $options);
    }
    
  • πŸ‡±πŸ‡ΉLithuania matask Vilnius
  • Please submit this as a merge request so the bots can test it. Even though πŸ“Œ Make tests pass Active exists we need to know if there are new failures. This itself may need some regression tests added.

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦
  • πŸ‡±πŸ‡ΉLithuania matask Vilnius

    Upon further review and thorough testing, the item-element-is-not-displayed.patch mentioned in comment #2 does not resolve the issue.

  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    Whether the item has #states does not impact whether an item is visible on view.

    You need to explicitly state the item should be visible when viewed via

    #display_on': both
    
    check_this_to_show_the_item:
      '#type': checkbox
      '#title': 'Check this to show the Item'
    item:
      '#type': item
      '#title': Item
      '#states':
        visible:
          ':input[name="check_this_to_show_the_item"]':
            checked: true
      '#display_on': both
      '#markup': '<p>This is the item to be shown.</p>'
    

  • πŸ‡±πŸ‡ΉLithuania matask Vilnius

    Thank you for your suggestion to use #display_on: both. However, the issue still persists. Despite setting all Item elements with #display_on: both, they are not displayed in the preview pane.

    I have double-checked the configuration to ensure that the #display_on property is correctly set for all Item elements. I've also attached the test form's configuration and screenshots illustrating the problem.

      checbox:
        '#type': checkbox
        '#title': Checbox
      checbox_item:
        '#type': item
        '#title': 'Checbox item'
        '#states':
          visible:
            ':input[name="checbox"]':
              checked: true
        '#display_on': both
        '#markup': '<p>Information when checkbox is checked.</p>'
    

    Could you please advise on any additional steps I might need to take to resolve this issue?

    Thank you for your assistance.

  • πŸ‡±πŸ‡ΉLithuania matask Vilnius
Production build 0.71.5 2024