diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-05-31 16:38:36 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-05-31 16:38:36 +0000 |
commit | 0cf79f07b0be7bb9912dfe2a9f2f4c45d98ac41e (patch) | |
tree | 3852d48ffab4625110892c1fe90669d65839dc2d /actionpack/lib/action_view | |
parent | ff5c7c8c40ba24431ec5c9cdad23ddb9963d2c67 (diff) | |
download | rails-0cf79f07b0be7bb9912dfe2a9f2f4c45d98ac41e.tar.gz rails-0cf79f07b0be7bb9912dfe2a9f2f4c45d98ac41e.tar.bz2 rails-0cf79f07b0be7bb9912dfe2a9f2f4c45d98ac41e.zip |
Fixed that DateHelper#date_select should set the day to the 1st when its a hidden option and the month is visible (or invalid dates can be produced) [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6911 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rwxr-xr-x | actionpack/lib/action_view/helpers/date_helper.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 9806d51a87..c686982056 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -109,6 +109,9 @@ module ActionView # date_select("credit_card", "bill_due", :default => { :day => 20 }) # # The selects are prepared for multi-parameter assignment to an Active Record object. + # + # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that all month + # choices are valid. def date_select(object_name, method, options = {}) InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_date_select_tag(options) end @@ -122,6 +125,9 @@ module ActionView # time_select("post", "start_time", :include_seconds => true) # # The selects are prepared for multi-parameter assignment to an Active Record object. + # + # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that all month + # choices are valid. def time_select(object_name, method, options = {}) InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_time_select_tag(options) end @@ -350,7 +356,7 @@ module ActionView include DateHelper def to_date_select_tag(options = {}) - date_or_time_select options.merge(:discard_hour => true) + date_or_time_select(options.merge(:discard_hour => true)) end def to_time_select_tag(options = {}) @@ -381,8 +387,15 @@ module ActionView discard[:minute] = true if options[:discard_minute] or discard[:hour] discard[:second] = true unless options[:include_seconds] && !discard[:minute] + # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are valid + # (otherwise it could be 31 and february wouldn't be a valid date) + if discard[:day] && !discard[:month] + datetime = datetime.change(:day => 1) + end + # Maintain valid dates by including hidden fields for discarded elements [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) } + # Ensure proper ordering of :hour, :minute and :second [:hour, :minute, :second].each { |o| order.delete(o); order.push(o) } |