diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-21 22:18:07 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-21 22:18:07 +0000 |
commit | a81333f115c877fc59601f4e0766df4bdce4a8d8 (patch) | |
tree | c2d1cfc1529a6c74e41680a427b0926fc9a78d52 /actionpack | |
parent | 470fc0209699d70e9e2349d35f3210757a7a7d17 (diff) | |
download | rails-a81333f115c877fc59601f4e0766df4bdce4a8d8.tar.gz rails-a81333f115c877fc59601f4e0766df4bdce4a8d8.tar.bz2 rails-a81333f115c877fc59601f4e0766df4bdce4a8d8.zip |
Add :default option to time_zone_select. Closes #10590.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8473 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 5 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 13 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 28 |
3 files changed, 45 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index d8a1cc752c..f134fec599 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,3 +1,8 @@ +*SVN* + +* Add :default option to time_zone_select. #10590 [Matt Aimonetti] + + *2.0.2* (December 16th, 2007) * Added delete_via_redirect and put_via_redirect to integration testing #10497 [philodespotos] diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 0f1d2b02bf..67be4d81f0 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -131,6 +131,17 @@ module ActionView # to TimeZone. This may be used by users to specify a different time # zone model object. (See #time_zone_options_for_select for more # information.) + # Finally, this method supports a <tt>:default</tt> option, which selects + # a default TimeZone if the object's time zone is nil. + # + # Examples: + # time_zone_select( "user", "time_zone", nil, :include_blank => true) + # + # time_zone_select( "user", "time_zone", nil, :default => "Pacific Time (US & Canada)" ) + # + # time_zone_select( "user", 'time_zone', TimeZone.us_zones, :default => "Pacific Time (US & Canada)") + # + # time_zone_select( "user", "time_zone", TZInfo::Timezone.all.sort, :model => TZInfo::Timezone) def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {}) InstanceTag.new(object, method, self, nil, options.delete(:object)).to_time_zone_select_tag(priority_zones, options, html_options) end @@ -385,7 +396,7 @@ module ActionView value = value(object) content_tag("select", add_options( - time_zone_options_for_select(value, priority_zones, options[:model] || TimeZone), + time_zone_options_for_select(value || options[:default], priority_zones, options[:model] || TimeZone), options, value ), html_options ) diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index bd062057fa..966a00ff0b 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -1294,4 +1294,32 @@ COUNTRIES "</select>", html end + + def test_time_zone_select_with_default_time_zone_and_nil_value + @firm = Firm.new() + @firm.time_zone = nil + html = time_zone_select( "firm", "time_zone", nil, :default => 'B' ) + assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" + + "<option value=\"A\">A</option>\n" + + "<option value=\"B\" selected=\"selected\">B</option>\n" + + "<option value=\"C\">C</option>\n" + + "<option value=\"D\">D</option>\n" + + "<option value=\"E\">E</option>" + + "</select>", + html + end + + def test_time_zone_select_with_default_time_zone_and_value + @firm = Firm.new('D') + html = time_zone_select( "firm", "time_zone", nil, :default => 'B' ) + assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" + + "<option value=\"A\">A</option>\n" + + "<option value=\"B\">B</option>\n" + + "<option value=\"C\">C</option>\n" + + "<option value=\"D\" selected=\"selected\">D</option>\n" + + "<option value=\"E\">E</option>" + + "</select>", + html + end + end |