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.

Comments

theunraveler’s picture

Status: Active » Needs review
StatusFileSize
new1.07 KB

I was having this problem too. It turns out that the Panels module calls node_view() twice, which in turn renders the webform_client_form twice. That means that the HTML ID of the form is something like webform-client-form-{id}--2, since drupal_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.

grndlvl’s picture

StatusFileSize
new959 bytes

Re-rolled using relative paths.

theunraveler’s picture

StatusFileSize
new962 bytes

Whoops, looks like I messed up that regex a bit. Here's a better one.

theunraveler’s picture

StatusFileSize
new960 bytes

Sorry, one more small change to the regex.

theunraveler’s picture

StatusFileSize
new961 bytes

Wow, I apologize for totally cluttering this issue with mistakes, but here's a patch that should finally work.

quicksketch’s picture

Hi 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.

quicksketch’s picture

Actually 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.

quicksketch’s picture

Title: Conditions in panels don't work » Webforms rendered twice on one page do not work with same-page conditional actions (affecting Panels in some configs)

Retitling 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.

quicksketch’s picture

Status: Needs review » Needs work

This patch needs work to work correctly with hiding/showing fieldsets and other form elements.

quicksketch’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.