The ajax framework fails with the following uncaught type error
TypeError: new_content[effect.showEffect] is not a function
Source File: http://sandbox.dev/misc/ajax.js?v=7.12
Line: 533
I figured out its because the unexpected function, in my case, 'undefinedToggle" is not defined any where.
Am therefore, submitting a patch to include code that ensures that the referenced showEffect is indeed a function before being executed.
Current code
else if (effect.showEffect != 'show') {
new_content[effect.showEffect](effect.showSpeed);
}
New code
else if (effect.showEffect != 'show') {
if(typeof new_content[effect.showEffect] == 'function') {//make sure its a function b4 calling it
new_content[effect.showEffect](effect.showSpeed);
}
}
I landed on this while using the Hierarchical select contributed module which also has a bug http://drupal.org/node/1372300 for which I will be submitting a patch immediately after this one.
Comment | File | Size | Author |
---|---|---|---|
#7 | drupal-8.x-ajax-showeffect-not-function-1702132-3.patch | 519 bytes | samhassell |
#3 | drupal-7.14-ajax-showeffect-not-function-1702132-2.patch | 633 bytes | kwabi |
#1 | drupal-7.14-ajax-showeffect-not-function-1702132.patch | 619 bytes | kwabi |
Comments
Comment #1
kwabi CreditAttribution: kwabi commentedHere is the patch
Comment #2
nod_Thanks for the bug report, a few things though:
This is not critical, read the guidelines
Don't make up tags, you're already in the ajax component with a NR status
Bug fixes go to 8.x first then are eventually backported to 7.x
This is not how comments should be redacted, please refer to the coding standards
We are now using strict equals, === not ==.
This is a valid thing to test for, your code is most likely the issue though.
undefinedToggle
really sounds like you've got something wrong somewhere in your module/theme.Comment #3
kwabi CreditAttribution: kwabi commentedThanks Nod_
Well, true there might be something wrong with module/theme. However I think it would still be good to sure that we are really executing a function especially that we are trying to execute some function whose declaration we might not have control - I mean where a contrib module might not define the expected. I have also noticed that typeof checks are done somewhere else in the ajax.js
Here is an update to the earlier patch
Comment #5
nod_Actually you don't need the comment. It doesn't add anything, code is explicit enough.
Please make a patch for 8.x, not 7.x
Comment #6
nod_You can add the check in the else if above as well.
Comment #7
samhassell CreditAttribution: samhassell commentedpatch against 8.x with a combined else if.
Comment #9
Anonymous (not verified) CreditAttribution: Anonymous commented#3: drupal-7.14-ajax-showeffect-not-function-1702132-2.patch queued for re-testing.
Comment #10
tim.plunkett#7: drupal-8.x-ajax-showeffect-not-function-1702132-3.patch queued for re-testing.
Comment #10.0
tim.plunkettthe line number is 533, not 537
Comment #21
larowlanTriaged this as part of bug-smash
This only surfaces when somebody enters the wrong value for the 'effect' key in their #ajax definition.
So it's more of a DX affordance than a bug.
Because of that I think this should be classified as a task - if folks disagree, please drop it back to a bug.
Additionally, 8.9.x is security support only, so the lowest version this could go into is 9.1.x, so adjusting as such
Comment #22
larowlanDiscussed this with @quietone and we both felt that it would be better to get an error in this instance than have the system silently ignore it.
Although I guess that would just fallback to using show, which means no effect, so you'd get a visual queue.