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.

Comments

matask created an issue. See original summary.

matask’s picture

StatusFileSize
new819 bytes

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);
}
matask’s picture

Version: 6.2.2 » 6.2.x-dev
cilefen’s picture

Status: Active » Needs work
Issue tags: -form states, -webform element, -preview +Needs merge request

Please submit this as a merge request so the bots can test it. Even though #3481554: Make tests pass exists we need to know if there are new failures. This itself may need some regression tests added.

liam morland’s picture

Version: 6.2.x-dev » 6.3.x-dev
matask’s picture

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

jrockowitz’s picture

jrockowitz’s picture

Status: Needs work » Closed (works as designed)
StatusFileSize
new99.96 KB

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>'

matask’s picture

StatusFileSize
new5.74 KB
new23.59 KB
new15.2 KB

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.

matask’s picture

Status: Closed (works as designed) » Needs work
jrockowitz’s picture

Status: Needs work » Postponed (maintainer needs more info)
StatusFileSize
new5.05 KB

I am not able to replicate this issue using the attached webform based on #9.

jrockowitz’s picture

Please reopen if you can provide an example webform similar to #11 that can reproduce this issue.

jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.