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

Requiring translation files generates CSRF related error. #13

Open
pcriv opened this issue Jun 21, 2015 · 4 comments
Open

Requiring translation files generates CSRF related error. #13

pcriv opened this issue Jun 21, 2015 · 4 comments

Comments

@pcriv
Copy link

pcriv commented Jun 21, 2015

When i add


//= require pickadate/translations/es_ES

to application.js I get this error:

Can't verify CSRF token authenticity
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)

If i remove that line it works fine.

@sigvei
Copy link

sigvei commented Nov 10, 2015

I haven't got much to add as to why this happens, but I can confirm that this happens for me as well. Seems like a really weird bug.

@ghost
Copy link

ghost commented Dec 14, 2015

👍 Please fix this.

@harmdewit
Copy link

Here's a fix:

jQuery.extend( jQuery.fn.pickadate.defaults, {
    hiddenName: true
});

Explanation

When using translations the value being displayed are different from the the value being submitted by using different values for the options format and formatSubmit. This works by adding an hidden input with the same name + suffix to the end of the form like post[created_at]_hidden. Input names like these apparently cause errors like these in ruby servers and rails (see: amsul/pickadate.js#208)

By setting hiddenName: true this is fixed by just using adding an hidden input with the same name instead of adding the suffix. This is the best solution imo. If you want you can also fix this by removing the suffix with hiddenSuffix: "" and optionally set an hidden prefix with hiddenPrefix: "".

@harmdewit
Copy link

I would argue setting hiddenName to true by default, but i could imagine this would break things for users that like to upgrade and already rely on parsing values with the suffix/prefix.

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

No branches or pull requests

3 participants