I've set a couple of conditions in a webform. When I don't use them in a panel view everything works fine, but when I place it in a panel the fields that I hid with conditions. They just always show.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | webform-conditionals-panels-1738342-5.patch | 961 bytes | theunraveler |
| #4 | webform-conditionals-panels-1738342-4.patch | 960 bytes | theunraveler |
| #3 | webform-conditionals-panels-1738342-3.patch | 962 bytes | theunraveler |
| #2 | webform-conditionals-panels-1738342-2.patch | 959 bytes | grndlvl |
| #1 | webform-conditionals-panels-1738342-1.patch | 1.07 KB | theunraveler |
Comments
Comment #1
theunraveler commentedI was having this problem too. It turns out that the Panels module calls
node_view()twice, which in turn renders thewebform_client_formtwice. That means that the HTML ID of the form is something likewebform-client-form-{id}--2, sincedrupal_html_id()increments the ID each time. The conditionals JS does not know to also look for forms with these IDs.Attached is a patch that will apply conditional behaviors to all instances of a webform, regardless of how many times it is rendered. It essentially looks for IDs based on the regex
^webform-client-form-\d+.+$, which should match multiple instances of a webform. This seems to fix the problem, and doesn't seem to introduce a noticeable performance impact.Comment #2
grndlvl commentedRe-rolled using relative paths.
Comment #3
theunraveler commentedWhoops, looks like I messed up that regex a bit. Here's a better one.
Comment #4
theunraveler commentedSorry, one more small change to the regex.
Comment #5
theunraveler commentedWow, I apologize for totally cluttering this issue with mistakes, but here's a patch that should finally work.
Comment #6
quicksketchHi guys, thanks for looking into this issue. The obvious thing for me to ask here is: can you prevent panels from calling node_view() twice? Generating the entire form twice obviously isn't a very efficient way of rendering a page.
Comment #7
quicksketchActually maybe this would help with #2022869: Webforms rendered twice on one page do not work with same-page conditional actions, which may make this seem more legitimate. I've marked that issue duplicate. Though generally rendering twice is just a bad thing to have happening.
Comment #8
quicksketchRetitling for a more generic name. I'm surprised that just fixing the form ID matching would solve this problem, since all the individual form elements are also given different IDs when rendered more than once. At the very least, I would expect this to affect fieldsets hidden by conditionals, which I know work by element ID.
Comment #9
quicksketchThis patch needs work to work correctly with hiding/showing fieldsets and other form elements.
Comment #10
quicksketchThis has been fixed by #2059215: Replace use of IDs to classes on Webform wrappers to avoid duplicate IDs.