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
This commit is contained in:
parent
470fc02096
commit
a81333f115
@ -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]
|
||||
|
@ -131,6 +131,17 @@ def country_select(object, method, priority_countries = nil, options = {}, html_
|
||||
# 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 @@ def to_time_zone_select_tag(priority_zones, options, html_options)
|
||||
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
|
||||
)
|
||||
|
@ -1294,4 +1294,32 @@ def test_time_zone_select_with_priority_zones
|
||||
"</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
|
||||
|
Loading…
Reference in New Issue
Block a user