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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1737362-3-webform_ajax-links_binding.patch | 1.48 KB | David Stosik |
| #1 | webform_ajax_js_binding-1737362-1.patch | 633 bytes | albert volkman |
Comments
Comment #1
albert volkman commentedHere's a patch with the above suggested fix.
Comment #2
David Stosik commentedHello,
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
Comment #3
David Stosik commentedHi 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.
Comment #4
albert volkman commented@orourkedd's patch worked for me, but yours appears to work as well. So whichever makes more sense / is more performant.
Comment #5
David Stosik commentedOf 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
Comment #6
albert volkman commentedCool, well, then lets roll with yours :)
Comment #7
David Stosik commentedPatch committed to 1.x-dev.
1.1 version will get out soon, and include this patch too.
Thanks for your help!
David