This project is archived and is in readonly mode.

#2561 ✓duplicate
Chandra Sekar

Weird years list when year not selected

Reported by Chandra Sekar | April 24th, 2009 @ 06:20 PM | in 3.x

In a date_select field with :prompt => true, when no year is selected, values like -3 to 7 appear after validation.

The form also has other fields for which validation has failed. Also, depending on the month selected, the value selected and the content of the year combo varies.

Comments and changes to this ticket

  • Chandra Sekar

    Chandra Sekar April 24th, 2009 @ 06:33 PM

    • Tag changed from :prompttrue, date_select, year to date_select, year
  • Sam Oliver

    Sam Oliver April 26th, 2009 @ 05:16 PM

    This is happening because a ruby Date object is being happily created with a missing attribute.

    For example:

    
    User.new("date_of_birth(1i)"=>"", "date_of_birth(2i)"=>"12", "date_of_birth(3i)"=>"6")
    

    Will set date_of_birth to 0012-06-01

    Additionally, if the day is greater than 12, ActiveRecord::MultiparameterAssignmentErrors is raised (because day becomes month)

    Ideally the date would fail validates_presence_of if any of the attributes are missing. See the comments on a similar issue in http://dev.rubyonrails.org/ticke...

    This also affects the :include_blank option for the same reason

  • Sam Oliver

    Sam Oliver August 23rd, 2009 @ 10:00 PM

    • Tag changed from date_select, year to date_select, patch, year

    This patch includes tests that demonstrate this incorrect month assignment bug and some extra tests for missing attributes with datetimes in multiparameter attributes.

    I also noticed that creating/updating a 'date' column type with multiparameter attributes sets an empty year to 0001, whereas when with a 'datetime' column type, empty years are set to 2001. I'm not sure either of these defaults are ideal, but at least 2001 is less obviously wrong for many use cases. In either case it would make sense to have them consistent.

    To clean this up, the patch converts all dates to Times and back again. This means the default year for a date set via multiparameter attributes will change from 0001 to 2001 and will be handled in the same way as 'datetime' columns.

    With regard to Chandra's specific problem, this won't totally solve it (by default 2001 would be the center year instead of 1 though). But adding :start_year and :end_year should get around that.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Sam Oliver

    Sam Oliver August 24th, 2010 @ 11:11 PM

    • Importance changed from “” to “”
  • Aditya Sanghi

    Aditya Sanghi October 17th, 2010 @ 07:43 PM

    • State changed from “new” to “duplicate”

    Please see ticket #4346 where we're still discussing this issue after 2 years. We've provided a patch with many more tests and comprehensively covers date/time/datetime issues as well as blank and nil positional parameters among other issues.

    Marking this as duplicate. Please provide your comments and review on #4346.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages