Steps to repeat:
I created a module that reloads the page using ajax. Its loads the content, then runs Drupal.attachBehaviors. When an ajax enabled webform submits, it attaches the behavior 'webform_ajax' to Drupal.behaviors by including the javascript file 'webform_ajax.js' in webform_ajax.module (line 214). If I then reload the page via ajax and reattach the behaviors to the newly loaded region, I get an error: Uncaught TypeError: Cannot read property 'nid' of undefined (webform_ajax.js - line 33).

The problem:
The problem is that it is assumed that this behavior will only be executed when the form is submitted via ajax and that there will always be the appropriate 'Return to Form' link in the loaded area. If another element on the page is loaded via ajax before the page is refreshed after an ajax enabled webform submit, the appropriate links will not be present.

My suggestion:
Add the following line below line 29:

if(typeof wrapper_id === 'undefined') return;

This ensures that only links within $('[id^=webform-ajax-wrapper]') are be ajaxified.

Comments

albert volkman’s picture

Assigned: orourkedd » Unassigned
Status: Active » Needs review
StatusFileSize
new633 bytes

Here's a patch with the above suggested fix.

David Stosik’s picture

Status: Needs review » Needs work

Hello,

Did you test your patch? It seems like the line you added is a bit too high in the code (see next line, where wrapper_id is set). Setting to "needs work" for now.

Thanks,
David

David Stosik’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB

Hi again,

Here is a patch that may do the trick, can you please test it and tell me if it works? If it does, I'll commit it soon.

Thanks,
David

This patch is part of the #1day1patch initiative.

albert volkman’s picture

Status: Needs review » Reviewed & tested by the community

@orourkedd's patch worked for me, but yours appears to work as well. So whichever makes more sense / is more performant.

David Stosik’s picture

Of course orourkedd's tip works, but your patch file does not. Well, it fixes this current issue's problem, but it introduces a regression.
In your patch, wrapper_id is always undefined (see how this variable is defined just below the line you added?), which means that the code always prematurely returns, even on cases it needs to apply Ajax behavior to the "Go back to form" link.

Regards,

David

albert volkman’s picture

Cool, well, then lets roll with yours :)

David Stosik’s picture

Status: Reviewed & tested by the community » Fixed

Patch committed to 1.x-dev.

1.1 version will get out soon, and include this patch too.

Thanks for your help!

David

Status: Fixed » Closed (fixed)

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