jquery-validation-rails
jquery-validation-rails copied to clipboard
jQuery Validate not setting correct language
I'm trying to validate a form with jQuery validate but it's doesn't seem to be returning error messages in the correct language.
In my Rails app, I have:
gem 'jquery-validation-rails'
application.js
//= require rails-ujs
//= require turbolinks
//= require jquery
//= require bootstrap-sprockets
//= require jquery.validate
//= require jquery.validate.localization/messages_it
//= require jquery.validate.localization/messages_ja
//= require_tree .
I call the validator with:
document.addEventListener 'turbolinks:load', ->
$("#contact-form").validate
submitHandler: (form) ->
form.submit()
$('#first_name').rules 'add',
required: true,
maxlength: 15
$('#last_name').rules 'add',
required: true,
maxlength: 15
$('#entry_email').rules 'add',
required: true,
maxlength: 60
$('#phone-number').rules 'add',
required: true,
digits: true
I am seeing the error messages, but they appear in Japanese even if I switch the page locale to en
or it
.
The language that appears is basically the last one I set in my application.js file. So if I remove //= require jquery.validate.localization/messages_ja
then I get error messages in Italian.
How can I get error messages on a per-locale basis?
Any help on fixing this would be much appreciated!
Thanks in advance
https://stackoverflow.com/questions/49150000/jquery-validate-not-setting-correct-language answer is here if someone needs it