adzap / validates_timeliness

Date and time validation plugin for ActiveModel and Rails. Supports multiple ORMs and allows custom date/time formats.
MIT License
1.59k stars 227 forks source link

Way to hide attribute name from error message? #149

Closed manojmj92 closed 6 years ago

manojmj92 commented 7 years ago

When I try to save an attribute (say, birthday) with invalid date, I get the following validation error on the form

birthday is not a valid date.

I need a way to hide the birthday part from the error message. Exposing my attribute name doesn't seem fit to me. For eg: My database column could be named just bd or birth or anything and showing bd is not a valid date seems inappropriate.

Anyway to do this?

titanium-cranium commented 7 years ago

I think if you just add the message after the validation it overrides the default message e.g. validates_date :birthday, message => 'Not a valid date'

adzap commented 6 years ago

There is no feature in ActiveRecord to remove the attribute name when displaying errors using full_messages which is the default for form inputs I believe. You'd need to display the individual error message per attribute.

See Rails Guides

aquellier commented 5 years ago

Hey I have the same problem, I've checked the rails guide but couldn't find my answer.

Usually I would define a custom method with sth like this errors.add(:base, 'You must be at least 18 years old') but I don't know how to do it here.

Is there any way to do the same with the gem?

adzap commented 5 years ago

Does any other field you are validating that is not a datetime show the error message in a different way?