gform.initializeOnLoaded is not a function [RESOLVED]

After the recent update I’m getting the following in my error console on all pages. This occurs whether there is a form on the page or not, with all caching and minification disabled.

Uncaught TypeError: gform.initializeOnLoaded is not a function - https://redacted.com/wp-content/plugins/gravityforms/js/gravityforms.min.js?ver=2.5.9: 1

Anyone else running into this? Thanks

1 Like

Can you provide a link to a page with this issue?

I am also running into this on a development site with 2.5.9.1 (also happened with 2.5.9 and 2.5.8). | Contact (on this page the form does not display). We have disabled minification of CSS+JS, turned off deferring or delaying JS scripts in WP-Rocket, etc.

The console errors are:

conditional_logic.min.js:1 Uncaught TypeError: gform.addAction is not a function
at conditional_logic.min.js:1
(index):850 Uncaught TypeError: gform.initializeOnLoaded is not a function
at HTMLDocument. ((index):850)
(index):855 Uncaught TypeError: gform.initializeOnLoaded is not a function
at HTMLDocument. ((index):855)

Viewing the page source code I found the theme or another plugin is wrapping the form scripts in DOMContentLoaded event listners, probably using an approach like this: Make Gravity Forms' JavaScript load in the footer

That code isn’t compatible with Gravity Forms 2.5+; the scripts are already deferred and wrapped in custom event listeners so the custom code used to implement the DOMContentLoaded change needs to be removed.

If you aren’t sure which theme or plugin is making the change you might need to run through a conflict test: https://docs.gravityforms.com/testing-for-a-themeplugin-conflict/

I love finding code that is circa 2018 in a functions file. Thanks for the tip, this fixed our issue.

1 Like

Thanks for the responses. We did have the following in place to push scripts in the footer:

add_filter( 'gform_init_scripts_footer', '__return_true' );

I have removed that for now. Still running into the same error unfortunately. I’ll DM the URL.

Doesn’t look I can DM, here’s a temporary link to the site:
https://www.temporary-url.com/77FFBF

Thanks!

@martym the page is showing cached files for both the page and for many of the javascript assets being loaded. These are showing as powered by WP Super Cache and Autoptimize. Please Reference: Handling Page Caching & Minification and ensure you’re not getting served cached pages after making such changes.

1 Like

Thanks Joshua!

I have tested with all caching and optimization off and the issue still persists. I’ll investigate down that road further and see if I can make progress.

Is there a comprehensive list of files to avoid caching/minifying for current version of GF? I think we had all the right rules in place previously but perhaps with recent GF updates the lists need to be updated. Thanks again for your help!

I am seeing a similar issue getting caught in our bug reporter (Sentry). It seems to be happening primarily with mobile browsers on mobile devices globally.

GF is loading external scripts like gravityforms.min.js and conditonal_logic.js with the “defer” attribute. But there is an inline script calling gform.initializeOnLoaded and conditoinal_logic is calling gform.addAction.

I’m not a JS master, but from what have found this does not seem to be a good implementation – the inline JS is executed before the deferred scripts have a chance to load? seems like it should have some sort of wrapper to defer execution of the inline scripts until after all the deferred external scripts have been loaded.

Again, I’m seeing this mostly with mobile devices (reporting as Chrome 90+) on international networks – doesn’t happen on desktops, or on my devices. Which makes me wonder if the connection is slow enough in some places (or not using http/2) to cause the deferred scripts to load in a different order.

1 Like

After more extensive troubleshooting I can rule out any caching, aggregation or minification as the issue.

Console debug points to the following line involving recaptcha I believe:

Uncaught TypeError: gform.initializeOnLoaded is not a function
gravityforms.min.js:1094

gform.initializeOnLoaded(gform.recaptcha.renderOnRecaptchaLoaded), jQuery(document).on('gform_post_render', gform.recaptcha.renderOnRecaptchaLoaded), window.renderRecaptcha = gform.recaptcha.renderRecaptcha, window.gformIsRecaptchaPending = gform.recaptcha.gformIsRecaptchaPending, function (h, v) {
  h.uploaders = {
  };

That function should be defined in an inline script located in the page header before any of the form js files are included. If that inline script is missing it indicates there is a theme or plugin conflict which you can test for using the steps here: https://docs.gravityforms.com/testing-for-a-themeplugin-conflict/

I found a solution to prevent this error from happening.
I use wpDataTables shortcodes on my website so Gravity Forms scripts are registered and enqueued after the execution of localize_hook_vars.
I created a must-use plugin to call the gform_force_hooks_js_output filter to force printing JS in the page header:

<?php
add_filter( 'gform_force_hooks_js_output', '__return_true' );

Warning: Currently, the documentation of gform_force_hooks_js_output is wrong about the default value. The value passed to apply_filter() is false, so the default value is false.

1 Like

Benjamin, thank you so much for sharing this solution. It worked!! Much appreciated.

I like your must-use plugin approach. This code works if you place it in functions.php as well.

1 Like
© 2008 - 2021. Gravity Forms is a project by Rocketgenius Inc.