Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsley.remote loading problem #985

Closed
alessandroliveri opened this issue Sep 23, 2015 · 27 comments
Closed

Parsley.remote loading problem #985

alessandroliveri opened this issue Sep 23, 2015 · 27 comments

Comments

@alessandroliveri
Copy link

Hi,
I upgraded to the last version and I use parsley.remote instead parsley but when I load the script through requirejs I have an error

Uncaught TypeError: Cannot read property 'on'

caused by this code at line 2065 in parsley.remote.js

window.Parsley.on('form:submit', function () { this._remoteCache = {}; });

Any idea?

@marcandre
Copy link
Collaborator

Are you loading just parsley.remote or both parsley and parsley.remote? It should be only the latter, but the instructions were misleading a while back...

@alessandroliveri
Copy link
Author

Only parsley.remote, this script seem include parsley

@marcandre
Copy link
Collaborator

Which version are you using?

@alessandroliveri
Copy link
Author

2.1.3, I tried the both solutions (import only parsley.remote or parsley and parlsley.remote) same result

@marcandre
Copy link
Collaborator

Ah ah!

That API is only for 2.2... Please check that out 😄

@alessandroliveri
Copy link
Author

Is not the master version the 2.1.3 version? I installed it via bower, how I can use the stable version?

@marcandre
Copy link
Collaborator

Well, 2.2 is still as a release candidate. Not too sure how to load it via bower, sorry.

@marcandre marcandre reopened this Sep 23, 2015
@marcandre
Copy link
Collaborator

Actually, I was wrong, window.Parsley.on should work in 2.1 anyways. Reopening

@marcandre
Copy link
Collaborator

I can't figure out why you'd get that with 2.1.3.
Can you double check that's the result you get in the console with window.Parsley.version?

I made a fiddle with that version and the remote code loads fine.

@marcandre
Copy link
Collaborator

The fiddle doesn't use requirejs though, so the problem has to be there... Sorry I can't easily help any further. If you could make a simple jsfiddle that would be great.

@alessandroliveri
Copy link
Author

http://jsfiddle.net/zfmph5w6/1/

As you can see in console the problem is with window.Parsley

@alessandroliveri
Copy link
Author

This problem occur only with the minified version, the not minified works fine.

@SebT
Copy link

SebT commented Oct 15, 2015

Hi,

I've installed parsley 2.1.3 via npm for browserify. I use require('parsleyjs/dist/parsley.remote') and I have the same error described in the original post.

I don't use the minified version and it still throws this error. But when I look at the code in parsley.remote.js, it seems pretty normal. Line 267 tries to access window.Parsley whereas it hasn't been defined yet.

Fix: I updated my npm dependency to https://github.com/guillaumepotier/Parsley.js.git#2.1.3 and it worked. The dist/parsley.remote.js file isn't the same in github (tag 2.1.3) and in the npm 2.1.3 release.

NOTE: With browserify, you must use ParsleyExtend.addAsyncValidator instead of Parsley.addAsyncValidator

Edit: Actually it doesn't work... I have no error and the validator is created but the async validator is never triggered. Here's my code:

window.ParsleyExtend.addAsyncValidator('login', function (xhr) {
    console.log(this.$element); // this is never called, and no network request is fired
    return 404 === xhr.status;
  },
  'myURL/{value}'
);

I added data-parsley-remote data-parsley-remote-validator="login" to my input and then call parsley on the parent form. Any help?

@khalwat
Copy link

khalwat commented Oct 18, 2015

I can confirm this. I have several sites that use Parsley (thank you!) with RequireJS. Using the same code, if I use the dist/parsley.min.js loaded via RequireJS, it fails in mysterious ways. Forms will simply not validate, with no console errors.

If I substitute in the dist/parsley.js version, it works sometimes, but fails other times.

I swapped out the entire RequireJS stack to just load the script via script tags, and everything works fine. So this is something with this version of Parsley and RequireJS.

Something is amiss with this version of Parsley and RequireJS.

@khalwat
Copy link

khalwat commented Oct 18, 2015

I tried substituting in the latest 2.2.0-rc2 version of Parsley, but it exhibits the same problem. Unfortunately, Parsley appears to be broken with RequireJS.

Unlike other posters in this thread, I'm not getting any errors. Parsley just doesn't work, whether initialized via JS or via data-parsley-validate.

Again, loading Parsley via a plain old <script> tag works; loading it via RequireJS fails.

I should note that I'm not using the remote version of Parsley.

@marcandre
Copy link
Collaborator

Sorry about this. We're very close of merging the es6 branch into master, which will resolve this loading issue (and also remove the non-remote version)...

@khalwat
Copy link

khalwat commented Oct 19, 2015

Thanks for the response. I look forward to it, I'll check regularly for the merge. In the meantime, my forms go on unvalidated :)

Thanks for all that you do.

@khalwat
Copy link

khalwat commented Oct 26, 2015

FWIW, I tried the es6 branch to see if that'd work for me... but it's still having intermittent issues loading properly when loaded via RequireJS.

@marcandre
Copy link
Collaborator

What issues exactly with the es6 branch, @khalwat ?

@khalwat
Copy link

khalwat commented Oct 29, 2015

@marcandre I may not have done it exactly right; I just replaced the dist folder from the release branch with the dist folder from the es6 branch.

The issues I had were very similar to what I was having with the release branch:

When loaded with RequireJS, sometimes, ParsleyJS would not work for underdetermined reasons. The symptoms are the Parsley won't validate blocks, and won't validate on form submission (it'll just hang).

In the same environment, if I load it via a <script> tag, it works properly.

I can give you a live staging URL to take a look at if it'll be helpful. Should I be doing anything other than grabbing parsley.min.js from dist from the es6 branch?

@khalwat
Copy link

khalwat commented Nov 3, 2015

@marcandre Let me know if there is anything I can do to assist you in tracking down this issue.

@marcandre
Copy link
Collaborator

A live link would help for sure.

The es6 branch landed in master, btw, so you can use the 2.2.0rc4 release.

Do you have an estimate at how often you get a problem?

@khalwat
Copy link

khalwat commented Nov 3, 2015

@marcandre I updated to 2.2.0rc4 and it seems to be working! Here is a live URL for you:

http://imawhale.com/apply

@marcandre
Copy link
Collaborator

Cool. So I'm closing this, but if anybody runs into issues with the current version, let me know!

@jessemorton
Copy link

I just installed it yesterday and have the issue as described at the top of @SebT's post trying to work with Parsley Remote.

@marcandre
Copy link
Collaborator

@jessemorton Please upgrade to 2.2.0rc4

@jessemorton
Copy link

Thanks for the speedy reply, @marcandre Maybe the NPM module just needs updating on your end? I installed via npm yesterday, but it looks like its v2.1.2. Doing npm update parsleyjs isn't accomplishing anything today.

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

No branches or pull requests

5 participants