aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-19 18:26:37 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-19 18:26:37 +0000
commit9b5ece87d429c9c78528ca5ce470422621a50ce6 (patch)
treedc1885099c466f698cefc9f7a9e6669a87cb727c /actionpack/lib
parent9a5d6d6388a20f29c63f85a95d215b0b34ea9cfd (diff)
downloadrails-9b5ece87d429c9c78528ca5ce470422621a50ce6.tar.gz
rails-9b5ece87d429c9c78528ca5ce470422621a50ce6.tar.bz2
rails-9b5ece87d429c9c78528ca5ce470422621a50ce6.zip
Added :order option for date_select that allows control over the order in which the date dropdowns is used and which of them should be used #619 [Tim Bates]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@695 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-xactionpack/lib/action_view/helpers/date_helper.rb37
1 files changed, 24 insertions, 13 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index f8c19d169d..c989100bbc 100755
--- a/actionpack/lib/action_view/helpers/date_helper.rb
+++ b/actionpack/lib/action_view/helpers/date_helper.rb
@@ -35,19 +35,23 @@ module ActionView
end
# Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute (identified by
- # +method+) on an object assigned to the template (identified by +object+). It's possible to tailor the selects through the +options+ hash,
- # which both accepts all the keys that each of the individual select builders does (like :use_month_numbers for select_month) and a range
- # of discard options. The discard options are <tt>:discard_month</tt> and <tt>:discard_day</tt>. Set to true, they'll drop the respective
- # select. Discarding the month select will also automatically discard the day select.
+ # +method+) on an object assigned to the template (identified by +object+). It's possible to tailor the selects through the +options+ hash,
+ # which both accepts all the keys that each of the individual select builders does (like :use_month_numbers for select_month) and a range of
+ # discard options. The discard options are <tt>:discard_year</tt>, <tt>:discard_month</tt> and <tt>:discard_day</tt>. Set to true, they'll
+ # drop the respective select. Discarding the month select will also automatically discard the day select. It's also possible to explicitly
+ # set the order of the tags using the <tt>:order</tt> option with an array of symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in
+ # the desired order. Symbols may be omitted and the respective select is not included.
+ #
+ # NOTE: Discarded selects will default to 1. So if no month select is available, January will be assumed.
#
- # NOTE: Discarded selects will default to 1. So if no month select is available, January will be assumed. Additionally, you can get the
- # month select before the year by setting :month_before_year to true in the options. This is especially useful for credit card forms.
# Examples:
#
# date_select("post", "written_on")
# date_select("post", "written_on", :start_year => 1995)
# date_select("post", "written_on", :start_year => 1995, :use_month_numbers => true,
# :discard_day => true, :include_blank => true)
+ # date_select("post", "written_on", :order => [:day, :month, :year])
+ # date_select("user", "birthday", :order => [:month, :day])
#
# The selects are prepared for multi-parameter assignment to an Active Record object.
def date_select(object, method, options = {})
@@ -219,15 +223,22 @@ module ActionView
date_select = ""
- if options[:month_before_year]
- date_select << select_month(date, options_with_prefix.call(2)) unless options[:discard_month]
- date_select << select_year(date, options_with_prefix.call(1))
- else
- date_select << select_year(date, options_with_prefix.call(1))
- date_select << select_month(date, options_with_prefix.call(2)) unless options[:discard_month]
+ if options[:month_before_year] # For backwards compatibility
+ options[:order] = [:month, :year, :day]
end
- date_select << select_day(date, options_with_prefix.call(3)) unless options[:discard_day] || options[:discard_month]
+ options[:order] ||= [:year, :month, :day]
+
+ position = {:year => 1, :month => 2, :day => 3}
+
+ discard = {}
+ discard[:year] = true if options[:discard_year]
+ discard[:month] = true if options[:discard_month]
+ discard[:day] = true if options[:discard_day] or options[:discard_month]
+
+ options[:order].each do |param|
+ date_select << self.send("select_#{param}", date, options_with_prefix.call(position[param])) unless discard[param]
+ end
return date_select
end