Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Conflict with Gravityforms - jQuery is not defined #1076

Closed
wishe opened this issue Sep 15, 2017 · 10 comments
Closed

Conflict with Gravityforms - jQuery is not defined #1076

wishe opened this issue Sep 15, 2017 · 10 comments

Comments

@wishe
Copy link

wishe commented Sep 15, 2017

How can this bug be reproduced?

  1. Install Gravity Forms
  2. Include it with Ajax on a page with a shortcode
  3. Try to submit the form
  4. Check the console

What did you expect to happen?
I would expect form validation to work via ajax and no console errors.

What happened instead?
Console shows multiple jQuery is not defined errors. I believe it is due to the way the newest version includes jQuery, with Webpack. Curious if anyone else have experienced a similar issue?

I tried to change where the Gravity Forms Javascript is enqueued to the footer but that did not help. When i remove the deregistering of the wordpress packed jQuery it works. But i dont want to be including 2 versions of jQuery on my site.

Please List the Following:

  • OS & version: Ubuntu 16.04
  • Node version (node -v) [Node v4+ is required] : v4.2.3
  • FoundationPress version (see line 3 in package.json): 2.10.1
  • Foundation version (see dependencies in package.json) : 6.4.1
@colin-marshall
Copy link
Collaborator

@wishe I was getting a different error when I followed the steps you provided to reproduce. It said a.indexOf is not a function. I was able to trace it to a deprecated call to the .load() function in Gravity Form's form-display.php which was removed in jQuery 3.0.

I was able to fix it by changing line 1037 in form-display.php from:
"jQuery('#gform_ajax_frame_{$form_id}').load( function(){"
to
"jQuery('#gform_ajax_frame_{$form_id}').on( 'load', function(){"

I'm kind of surprised that Gravity forms is still using the deprecated load() function, but I guess that's because whatever version of jQuery that WordPress currently uses by default is < 3.0 so it hasn't removed it yet.

If you change that line will it start working for you @wishe?

@wishe
Copy link
Author

wishe commented Sep 18, 2017

I am getting an error on the script tag "jQuery is not defined". Unfortunately the change your proposed does not do anything for me.

<script type='text/javascript'> jQuery(document).bind('gform_post_render', function(event, formId, currentPage){if(formId == 1) {} } );jQuery(document).bind('gform_post_conditional_logic', function(event, formId, fields, isInit){} );</script><script type='text/javascript'> jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [1, 1]) } ); </script></body>

@olefredrik
Copy link
Owner

Hi @wishe . I will close this issue, as issues regarding integration of third-party WordPress plugins are not supported.

@phylaxis
Copy link

phylaxis commented Nov 9, 2017

I know this a closed issue, but thought I'd provide some explanation and a solution for others who might run cross this conflict. I contacted Gravity Forms support and got this explanation:

Gravity Forms supports the version of jQuery which is included with WordPress, currently 1.12.4. Support for jQuery 3.0 will be added in time for WordPress updating their jQuery version to 3.0. In the meantime you'll want to ensure you are including the jQuery migrate script when using jQuery 3.0.

So the suggested "fix" is to enqueue the jQuery Migrate add-on, https://blog.jquery.com/2016/05/19/jquery-migrate-1-4-1-released-and-the-path-to-jquery-3-0/

@phylaxis
Copy link

phylaxis commented Nov 9, 2017

Here's the line I added to just below line 46 of the /library/enqueue-scripts.php

wp_enqueue_script( 'jquery-migrate', 'https://code.jquery.com/jquery-migrate-3.0.1.min.js', array('jquery'), '3.0.1', false );

@colin-marshall
Copy link
Collaborator

colin-marshall commented Nov 11, 2017

@phylaxis thanks for reporting this to Gravity Forms. Their response doesn't really make sense to me and is actually kind of frustrating because whoever responded to that didn't actually look into the issue and the suggested fix.

The load method has been deprecated since version 1.8. The on event handler (which would resolve the issue without jQuery migrate) has been included in jQuery since version 1.7. WordPress v3.3 (released in 2012!) was when WordPress started shipping with jQuery 1.7+.

The latest version of Gravity Forms requires "the latest version of WordPress" to work with it. There is really no good reason that I can see for them to not simply replace .load( function(){ with .on( 'load', function(){ at this point in time. There's no way that somebody using the latest version of Gravity Forms could also be using WordPress <= v3.2 without running into other problems, besides the fact that their requirements don't allow it. So essentially they are making life more difficult for people by denying a change that will have zero negative effects (as far as I can tell) on any of their users.

@phylaxis I would appreciate it if you could follow up with GF's support with the info I provided here and see if they change their tune. Thanks!

@phylaxis
Copy link

I believe their point is that, even though it's been deprecated, Wordpress (the latest version) still only includes jQuery 1.12.4 (which still allows the deprecated method) and also jQuery Migrate, so technically the "latest version of Wordpress". Crazy I know and I buy your logic more than theirs. I'll happily pass along your comments, but I doubt it will change anything on their end. Cheers!

@colin-marshall
Copy link
Collaborator

@phylaxis I appreciate that! Maybe when it's all laid out for them they'll see why it makes no sense to keep load, but ya, I'm not holding my breath.

@justinestrada
Copy link

Gravity Forms team please replace .load with .on('load'

@code23-isaac
Copy link

Gravity Forms team please replace .load with .on('load'

This seems to have been implemented by gravity forms now, on line 1049 of form_display.php

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants