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.
Elements that are hidden via states should not be visible on the preview page. It's confusing to the user to see fields there that he hasn't seen or filled out in the form.
Example form:
trigger:
'#type': checkbox
'#title': Trigger
hidden:
'#type': checkbox
'#title': Hidden
'#states':
visible:
':input[name="trigger"]':
checked: true
Preview page will show: "Hidden: No"
Comment | File | Size | Author |
---|---|---|---|
#18 | 2939414-18.patch | 15.01 KB | jrockowitz |
| |||
#16 | 2939414-16.patch | 11.9 KB | jrockowitz |
| |||
#13 | webform.webform.issue_2939414.yml | 3.68 KB | jrockowitz |
#13 | 2939414-13.patch | 4.64 KB | jrockowitz |
|
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI don't think hidden elements should support #states.
Hidden elements can currently be excluded from the preview page and email.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI miss read the issue. I don't see any easy solution.
Comment #4
Ice-D CreditAttribution: Ice-D commentedSorry, by "hidden" I meant "invisible". Will change the title. Do you think it is an issue worth tackling?
Comment #5
Ice-D CreditAttribution: Ice-D commentedComment #6
Ice-D CreditAttribution: Ice-D commentedThe problem mainly concerns checkboxes and radios. Other elements can be hidden on the preview page if empty. (Invisble elements are "empty" to webform)
Can we have an option to hide checkbox/radio elements on the preview if they are not checked?
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThere is definitely an issue here because a hidden checkbox should be stored as a NULL value and a visible unchecked checkbox should be stored as FALSE.
Comment #8
Ice-D CreditAttribution: Ice-D commentedAny new insights on this?
Comment #9
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedNullifying conditionally hidden elements is going to require a bit of work and a lot of testing. If we are not careful we could cause people to lose data.
Comment #10
nodecode CreditAttribution: nodecode commentedMy forms have quite a few conditionally-hidden elements and the Preview/Submissions are fairly indecipherable both for the person filling out the form and the person receiving the submission. I'm not the best at debugging code but I do understand it and I'm willing to look into it if you need a hand. Otherwise I'm watching this issue closely and here to test thoroughly.
Comment #11
Ice-D CreditAttribution: Ice-D commentedMy temporary solution is to hide all the checkboxes that aren't checked. Just put this in a custom module.
Comment #12
nodecode CreditAttribution: nodecode commented@Ice-D, for me it's also affecting Text fields which contain default values but are hidden so they shouldn't be included in the Preview/Submission.
@jrockowitz, If you're wary about this being fixed and people losing data, perhaps there could be a checkbox in the settings to "Exclude hidden elements" from the Preview they same way there exists "Exclude empty elements". Just a thought.
Comment #13
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedAttached is a test webform and a patch that checks if an element is conditionally hidden when it is being viewed.
It is possible that this pretty basic patch could solve a lot of problems. Once all the existing tests pass I will add some additional test coverage.
Comment #16
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #18
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #20
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #21
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed the patch. Please download the latest dev release to review.
Comment #22
nodecode CreditAttribution: nodecode commentedIt seems to be working well in my tests of more complex forms.
Comment #23
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@nodecode The issue that really needs some QA is #2918669: Elements separated by conditional inside multistep wizard are both saved to submission