Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I set a message element to be "Visible" based on the value in a select list, the message is not hidden automatically when that value is not selected. I don't know if this is consistent with other combinations of elements. All I know is that it was working as expected before I updated dev from a previous version about a month old (around beta25). This is also the case with 5.0-rc1.
Reproduce the issue with this YAML code:
my_time:
'#type': time
'#title': 'Time (choose 9:00 AM to reveal message)'
'#default_value': '08:00:00'
'#timepicker': true
'#time_format': 'g:i A'
'#step': '300'
hidden_message:
'#type': message
'#states':
visible:
':input[name="my_time"]':
value: '9:00 AM'
'#message_type': warning
'#message_message': 'This message should be hidden until you select "9:00 AM" above, but it is not working.'
'#message_close': true
actions:
'#type': webform_actions
'#title': 'Submit button(s)'
Comment | File | Size | Author |
---|---|---|---|
#2 | 2937175-2.patch | 693 bytes | jrockowitz |
| |||
#2 | webform.webform.issue_2937175.yml | 3.48 KB | jrockowitz |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached webform replicates the issue.
The issue is the message is being display after #states has hidden it.
The attached patch addresses this issue.
Comment #3
nodecode CreditAttribution: nodecode commentedI'd love to test but I have no idea how to patch using Composer without corrupting my site.
Comment #4
nodecode CreditAttribution: nodecode commentedComment #5
nodecode CreditAttribution: nodecode commentedOk I gave up on patching with Composer and used curl. The patch in #2 works for me!
Comment #6
nodecode CreditAttribution: nodecode commentedOn second thought, there is a weird issue I'm seeing where the hidden message is visible for a moment then it disappears. Shouldn't it be invisible by default? It's really clunky the way it works now. Not sure if this was the case with 5.0-beta25.
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedDrupal #states API does show elements before triggering the conditional hide/show logic. There might some CSS magic that we can use to fix this.
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe updated attached patch fixes the javascript issue.
The displaying of elements before they are hidden is core behavior that has always been there. I am noticing it more in 8.5 with BigPipe enabled because BigPipe's JS is executing before #states API hides any form elements.
The below CSS does hide messages with visible/hidden #states by default. The problem is ff JavaScript is disabled the message will never be displayed. I am not ready to commit this type of solution to the Webform module.
I think we should fix this issue and then open a new issue related to hidden elements are appearing as a page being rendered.
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed the patch. Please download the latest dev release to review.
The issue with elements with #states being visible while a page is loading should be handled in a new ticket.