When multiple conditionnal forms are printed on the same page, only the first one works.

I think I traced it to this function :

Drupal.webform_conditional.getComponentsByName = function (field_name){
    // check to save jquery calls
    if(Drupal.webform_conditional.components[field_name]){
        return Drupal.webform_conditional.components[field_name];
    }
    // don't overwrite original name to store for caching
    var css_field_name = "[" + field_name + "]";
    var nid = Drupal.settings.webform_conditional.nid;
    if(nid instanceof Array){
        nid = Drupal.settings.webform_conditional.nid[0];
    }
    return Drupal.webform_conditional.components[field_name] = $("#webform-client-form-" + nid + " *[name*='"+css_field_name+"']");
};

More specifically :

 var nid = Drupal.settings.webform_conditional.nid;
    if(nid instanceof Array){
        nid = Drupal.settings.webform_conditional.nid[0];
    }
    return Drupal.webform_conditional.components[field_name] = $("#webform-client-form-" + nid + " *[name*='"+css_field_name+"']");

If I understand well, when there are several forms on the same page, there is a problem because for every fields, you take the first form to build the identifier ( $("#webform-client-form-" + nid + " *[name*='"+css_field_name+"']")

Wouldn't be better to use the parent ?

Comments

davidpetit’s picture

Hi Seb ! I agree we should find directly the ID of the parent form with jQuery parents() starting from the field current item.

So I propose this patch.

davidpetit’s picture

Status: Active » Needs review
tedbow’s picture

Priority: Normal » Minor
Status: Needs review » Needs work

@DavidPetit thanks for catching this. I think your patch will only work though if 2 webforms on the same page don't have any component that have the same key. If they have the same key if it still might not get the right one.

davidpetit’s picture

@tedbow
I can't see what you mean; because since the form_id is unique, even if the key is the same, we will have:
"#form_id_nid_1 field_name" and "#form_id_nid_2 field_name" so the jquery selector are always unique and it's good this way.

I have tried this with same key on each component in the two forms and it seems to be working.
Maybe we are not talking about the same thing ?

ashrafabed’s picture

Here's a workaround for part of the issue:

   // Remove empty webform conditions -- written this way so it can be added via a third module:
   if (isset($form['#webform_conditional_js']) && (!is_array($form['#webform_conditional_js']['fields']))) {
     unset($form['#webform_conditional_js']);
     if ($webform_after_build_key = array_search('webform_conditional_add_js', $form['#after_build'])) {
       unset($form['#after_build'][$webform_after_build_key]);
     }
   } 
   // end fix

This fix addresses the case where there are multiple webforms on one page, and only one of the webforms use conditionals.

densolis’s picture

All,

I am helping tedbow with this module. I will be talking with him on Monday and bring this to his attention. One of us will update this status next week.

Dennis

simone960’s picture

I encountered the same problem in 7.x-1.0-beta1. Any patch for this?