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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kwabi’s picture

Status: Active » Needs review
Issue tags: +Ajax, +ajax error
FileSize
619 bytes

Here is the patch

nod_’s picture

Version: 7.14 » 8.x-dev
Priority: Critical » Normal
Status: Needs review » Needs work
Issue tags: -Ajax, -ajax error +Needs backport to D7

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.

kwabi’s picture

Status: Needs work » Needs review
FileSize
633 bytes

Thanks 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

Status: Needs review » Needs work

The last submitted patch, drupal-7.14-ajax-showeffect-not-function-1702132-2.patch, failed testing.

nod_’s picture

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

nod_’s picture

You can add the check in the else if above as well.

samhassell’s picture

Status: Needs work » Needs review
FileSize
519 bytes

patch against 8.x with a combined else if.

Anonymous’s picture

tim.plunkett’s picture

tim.plunkett’s picture

Issue summary: View changes

the line number is 533, not 537

Status: Needs review » Needs work

The last submitted patch, 7: drupal-8.x-ajax-showeffect-not-function-1702132-3.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

larowlan’s picture

Version: 8.9.x-dev » 9.1.x-dev
Category: Bug report » Task
Issue summary: View changes
Issue tags: +Bug Smash Initiative, +DX (Developer Experience)

Triaged 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

larowlan’s picture

Discussed 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.

Version: 9.1.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.