-
Notifications
You must be signed in to change notification settings - Fork 82
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
Differentiating between blank
and not_a_date
#62
Comments
Yup - I've been bitten by that one. The solution is to use date: { allow_blank: true } So the date validation won't get run if date is not present. |
I have something like validates :effective_to, date: { allow_blank: true, after: :effective_from } It complains if effective_to is blank :( |
@mlt Here's a section of code involved, which suggests that your code above should work: date_validator/lib/active_model/validations/date_validator.rb Lines 52 to 71 in 0a1f7ae
A |
My bad! I was messing around with parameter p[:effective_to] = DateTime::Infinity if p.fetch(:effective_to, '').blank? Note, that validates :effective_to, date: { after: :effective_from }, unless: Proc.new{ |p| p.effective_to.blank? } worked fine with blank (actually infinite) parameter. It seems to me they should be equivalent. |
Hello,
I'm trying to set up date validation on a field that requires a valid date be input.
validates :dob, date: true, presence: true
renders both theblank
andnot_a_date
messages.I am working on a fork that would change the functionality so that passing:
nil
tovalidates :dob, date: true
wouldreturn en.errors.messages.blank
'bob'
tovalidates :dob, date: true
wouldreturn en.errors.messages.not_a_date
Is this something that would be welcomed as a pull request or should I keep it separate?
The text was updated successfully, but these errors were encountered: