Problem

To avoid double html IDs drupal_html_id adds a number to the html id when it is already in the static cache.

The JS in Webform Conditional assumes that #webform-client-form-[NID] is only used once. This is a problem on AJAXed forms, or when the module is used in combination with Panelizer, or just in general when you do something weird in the theme layer.

Solution

The attached patch solves the issue. It search on forms that have an ID that starts with 'webform-client-form-[NID]', so that it will match 'webform-client-form-[NID]' and 'webform-client-form-[NID]--2'.

CommentFileSizeAuthor
webform_conditional_htmlid_start_fix.patch887 bytesfrans

Comments

tedbow’s picture

@Frans, Thanks for the patch. It seems to work on my existing test forms. But could give a concrete example of how to make/test a form that breaks without this patch. I would like to be able to test that it actually fixes a problem before I commit it.

frans’s picture

It happens on several occasions. I must admit that it indicates that something else is wrong. It could happen when ajax is implemented wrong. But here is my case.

I installed module Panelizer and 'panelized' the webform node. Then I put the webform part of the node in another region on the content screen of the panelizer settings(not sure if that is needed). Voila... a wrongly generated htmlid.

I think the reason is the internal working of panelizer; it probably first renders the body (generating the normal htmlid), and then a seperate render for the webform part, causing a second render and a htmlid that is wrong.

I know... the patch fixes something that is not a problem in this module. But I also think that assuming a html id is correct in the code is not always true (bad themers can easily break this module). Maybe it is better to add an identifier or class to the triggering element, so that these issues can be completely avoided?