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

Application Defined Messages Not Being Used #225

Closed
gyarra opened this issue Nov 21, 2011 · 3 comments
Closed

Application Defined Messages Not Being Used #225

gyarra opened this issue Nov 21, 2011 · 3 comments

Comments

@gyarra
Copy link

gyarra commented Nov 21, 2011

Hi,

I'm using Rails 3.0.5 and client_side_validations 3.0.5. I'm seeing the default Rails error message displayed instead of my custom error messages.

Code:

 validates :address1, :length => {:minimum => 5, :message => "Address must be at least 5 characters"} 

When the address1 field fails client-side validation, the default message "is too short..." displays instead of my defined message "Address must be ...". If I submit the form so the page reloads with errors, the error I specified is correctly displayed next to the field. But as soon as I modify the field and validation fails again, the default error is again rendered.

Please let me know if this is expected behavior. If not I'll dig deeper.

Thanks,
Gabe

@gyarra
Copy link
Author

gyarra commented Nov 22, 2011

OK, dug a little deeper. I'm thinking this is caused by a translation issue. Possibly.

On line 14 of client_side_validations/active_model/length.rb


from the console, I run:

adr.errors.generate_message(:address1, :minimum, 3) ```

Which generates:
 => "translation missing: en.activerecord.errors.models.address.attributes.address1.minimum"

Not totally sure that the parameters are correct in the method call, but I played around with a bunch.  I'm not really sure why the message would be translated.  generate_message looks at I18n, but I would think since there's nothing there, it would return the initial message ...

@gyarra
Copy link
Author

gyarra commented Nov 22, 2011

OK, figured out a fix, but I think it's still a bug. At least it's not the behavior I'd expect.

If I specify the error message in en.yml it's picked up by client_side_validations. So the gem is ignoring messages defined as options in the validation methods themselves and instead looking in the localization file, even though I'm not using I18n. This is a different behavior from the validation in the Rails code, which picks up the :message option.

If this is the expected behavior it should probably be documented in the wiki. If not, I'm happy to look into a fix.

Also, I don't want to seem too critical. This gem is great and I'm very happy with it. Thanks for making it!

@bcardarella
Copy link
Contributor

Yes, this is a bug. Thank-you. Sorry it took so long for me to get to it.

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

2 participants