guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

Please use jQuery to refer to jQuery and not $ #685

Closed kennypu closed 9 years ago

kennypu commented 9 years ago

including parsley.min.js with a regular Wordpress install will cause an 'undefined is not a function', since the file is using $ to reference jQuery.

gideonheilbron commented 9 years ago

You should deregister the jQuery Wordpress is using and register the 'normal' one. Don't forget to NOT deregister when in admin. This will solve your problem.

zslabs commented 9 years ago

@gideonheilbron A vast majority of WordPress users may:

  1. Stop using ParsleyJS because it's not compatible straight out of the box and assume it's a defunct plugin
  2. Deregister the core jQuery and reregister a version number manually (which is a horrible decision for future maintenance compared to using a plugin I wrote; WP jQuery Plus
  3. Continue to post on Github the same exact issue until something is specifically set in the docs or it is addressed.

I believe you're saying jQuery noConflict is the issue here, right?

Also - you can't deregister jQuery in the admin anymore.

kennypu commented 9 years ago

@gideonheilbron that is not a good solution, as it may break any wordpress plugins that rely on jQuery Wordpress.

It is bad practice to refer to $ anyways as it can be used for other libraries, not only jquery. I've seen it mentioned from time and time again (eg. http://www.sitepoint.com/10-tips-better-jquery-plugins/ #4)

guillaumepotier commented 9 years ago

Ok guys,

I tried to fix the non AMD jQuery requirement in order to not break things in Wordpress. Could you have a try at this version please? -> https://raw.githubusercontent.com/guillaumepotier/Parsley.js/master/dist/parsley.js

kennypu commented 9 years ago

just tested on fresh wordpress install, yup it works (bottom left is the form): http://imgur.com/rGq4ssf,bV97Oy0

In comparison, ver 2.0.2 parsley.min.js (downloaded from the site) gave an error as shown: http://imgur.com/rGq4ssf,bV97Oy0#1

guillaumepotier commented 9 years ago

Great, I just released it as 2.0.3. Thanks guys for your feedbacks, enjoy!

kennypu commented 9 years ago

thanks!!

zslabs commented 9 years ago

Thanks a lot!

On Jul 21, 2014, at 6:00 AM, Kentaro Rose notifications@github.com wrote:

thanks!!

— Reply to this email directly or view it on GitHub.

joelcdoyle commented 9 years ago

I am still having this issue with the latest version of WordPress, Bones theme, and the latest Parsley.js

How is that possible?

marcandre commented 9 years ago

But this is the official Parsley.js repo.

joelcdoyle commented 9 years ago

Yep, you're right. I got confused. I'm using Parsley 2.0.6, built just a few days ago. Did something change that would break this?

marcandre commented 9 years ago

I'm not familiar with wordpress, but did you include jQuery?

joelcdoyle commented 9 years ago

Btw, parsley require attributes still work, without calling

$('#myform').parsley();

But, data-parsley-equalto="#password" , for example, does not work. Plus, I get

undefined is not a function

if I try to call the above

joelcdoyle commented 9 years ago

jQuery is included in WordPress by default.

marcandre commented 9 years ago

Can you provide a link?

joelcdoyle commented 9 years ago

I wish I could, but it's a private project. :hankey: Sorry, I know that doesn't help.

joelcdoyle commented 9 years ago

Created a stack issue: http://stackoverflow.com/questions/28223575/parsley-js-in-wordpress-undefined-is-not-a-function

joelcdoyle commented 9 years ago

Thanks @marcandre. Changing the document ready function fixed my problem.