Using cck_blocks module breaks webform conditionals because of js being included twice. This is happening because of an issue in cck_blocks (#833730: Cck block display settings override basic node settings.). May be webform_conditional_add_js() should be protected against multiple inclusion like this:

function webform_conditional_add_js(&$form, $form_state) {
  static $js_added;
  if (!isset($js_added)) {
    drupal_add_js(array('webform_conditional' => $form['#webform_conditional_js']), "setting");
    drupal_add_js(drupal_get_path('module', 'webform_conditional') . '/webform_conditional.js');
    $js_added = TRUE;
  }
  return $form;
}

(patch included)

Perhaps it would be worth waiting until the issue with cck_blocks was resolved. But since there is such a simple (and widely used) way to avoid similar problems in the future, why not use it?

CommentFileSizeAuthor
webform_conditional_js_fix.patch941 bytesdan.nsk

Comments

tedbow’s picture

@ dan.nsk , thanks for the patch but just wondering...

If the goal of the patch is to be able to have 2 Webforms that use this module shown on one page I am not sure it will work.

The patch will stop the javascript from being add twice. I don't think the 2 webforms would actually work.

any ideas?

dan.nsk’s picture

No, in my case even a single webform stops working because of the issue mentioned above. The problem is definitely with cck_blocks, but when the issue is resolved (and backported to 6.x), who will guarantee that another bug will not break webform conditionals again.

thsutton’s picture

I've just created #1484932: Conditional fields are not shown in webform displayed in blocks which also results in broken Javascript, there due to changes IDs when a webform is displayed in a block.

Perhaps the approach to generating and including JS needs to be revised? Making `Drupal.settings.webform_conditional` a hash would more readily support multiple forms on the same page (multiple copies of the same form even, as in my issue):

  drupal_add_js(array('webform_conditional' => array( 
    $form['#id'] => $form['#webform_conditional_js'],
  )), array('type' => "setting", 'scope' => JS_DEFAULT));
DaPooch’s picture

Did the 6x version of the cck_blocks issue ever get back ported? I can verify that the above patch works for me, but I'd like to get cck_blocks running right too. I can't seem to tell if it was ever resolved for 6x.