Rails date validation reports wrongly formatted input as empty #6184

Closed
nathansamson opened this Issue May 6, 2012 · 1 comment

Projects

None yet

1 participant

@nathansamson

What:
A model with a date field.
Same model with validates :the_date, :date => true, :presence => true, :allow_nil => true

An input form with:
<input type="date" name="the_model[the_date]" />

A controller (TheModelController) with

def create
  the_object = TheModel.new params[:the_model]

  if the_object.save
    # Does not matter
  else
    # Display the_object errors to the user.
  end
end

Now the user has an older browser which does not support date input field, so he has to do it manually.
He enters this in the format 'dd-mm-yy'
The following errror is reported:
'can't be blank' Which is obviously wrong since the value is not blank.
Correct error should be something like: 'is not a date in the format of dd-mm-yyyy, for example 6-05-2012.' (the exact error message is up to I18n ofcourse).

I guess this won't happen in the "normal" case where the date input are 3 select boxes, but hey, we are not the 00's anymore but are already 2012 with modern browsers and jquery fallbacks.

Woops, seems that rails does not have date validation support, and that the bug is in the date_validatior gem I seem to be using...

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