Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Weird years list when year not selected

#2561

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.

Reported by Chandra Sekar · April 24th, 2009 @ 06:20 PM

State: duplicate
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Chandra Sekar
    Chandra Sekar
    • Tag changed from :prompttrue, date_select, year to date_select, year

    April 24th, 2009 @ 06:33 PM

  2. Sam Oliver
    Sam Oliver

    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

    April 26th, 2009 @ 05:16 PM

  3. Sam Oliver
    Sam Oliver
    • 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.

    August 23rd, 2009 @ 10:00 PM

  4. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  5. Sam Oliver
  6. Aditya Sanghi
    Aditya Sanghi
    • State changed from new to duplicate

    Please see ticket #4346 time_select not interpreting the multi-parameter correctly 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 time_select not interpreting the multi-parameter correctly.

    October 17th, 2010 @ 07:43 PM