Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8473

Show
Ignore:
Timestamp:
12/21/07 22:18:07 (9 months ago)
Author:
bitsweat
Message:

Add :default option to time_zone_select. Closes #10590.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r8429 r8473  
     1*SVN* 
     2 
     3* Add :default option to time_zone_select.  #10590 [Matt Aimonetti] 
     4 
     5 
    16*2.0.2* (December 16th, 2007) 
    27 
  • trunk/actionpack/lib/action_view/helpers/form_options_helper.rb

    r8277 r8473  
    132132      # zone model object. (See #time_zone_options_for_select for more 
    133133      # information.) 
     134      # Finally, this method supports a <tt>:default</tt> option, which selects 
     135      # a default TimeZone if the object's time zone is nil. 
     136      # 
     137      # Examples: 
     138      #   time_zone_select( "user", "time_zone", nil, :include_blank => true) 
     139      # 
     140      #   time_zone_select( "user", "time_zone", nil, :default => "Pacific Time (US & Canada)" ) 
     141      # 
     142      #   time_zone_select( "user", 'time_zone', TimeZone.us_zones, :default => "Pacific Time (US & Canada)") 
     143      # 
     144      #   time_zone_select( "user", "time_zone", TZInfo::Timezone.all.sort, :model => TZInfo::Timezone) 
    134145      def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {}) 
    135146        InstanceTag.new(object, method, self, nil, options.delete(:object)).to_time_zone_select_tag(priority_zones, options, html_options) 
     
    386397        content_tag("select", 
    387398          add_options( 
    388             time_zone_options_for_select(value, priority_zones, options[:model] || TimeZone), 
     399            time_zone_options_for_select(value || options[:default], priority_zones, options[:model] || TimeZone), 
    389400            options, value 
    390401          ), html_options 
  • trunk/actionpack/test/template/form_options_helper_test.rb

    r8465 r8473  
    12951295                 html 
    12961296  end 
     1297 
     1298  def test_time_zone_select_with_default_time_zone_and_nil_value 
     1299     @firm = Firm.new() 
     1300     @firm.time_zone = nil 
     1301      html = time_zone_select( "firm", "time_zone", nil, :default => 'B' ) 
     1302      assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" + 
     1303                   "<option value=\"A\">A</option>\n" + 
     1304                   "<option value=\"B\" selected=\"selected\">B</option>\n" + 
     1305                   "<option value=\"C\">C</option>\n" + 
     1306                   "<option value=\"D\">D</option>\n" + 
     1307                   "<option value=\"E\">E</option>" + 
     1308                   "</select>", 
     1309                   html 
     1310  end 
     1311 
     1312  def test_time_zone_select_with_default_time_zone_and_value 
     1313     @firm = Firm.new('D') 
     1314      html = time_zone_select( "firm", "time_zone", nil, :default => 'B' ) 
     1315      assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" + 
     1316                   "<option value=\"A\">A</option>\n" + 
     1317                   "<option value=\"B\">B</option>\n" + 
     1318                   "<option value=\"C\">C</option>\n" + 
     1319                   "<option value=\"D\" selected=\"selected\">D</option>\n" + 
     1320                   "<option value=\"E\">E</option>" + 
     1321                   "</select>", 
     1322                   html 
     1323  end 
     1324 
    12971325end