Skip to content

Rails date validation reports wrongly formatted input as empty #6184

@nathansamson

Description

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions