diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 8f845ce7e11877319f0d82480ea3bafaa8b6699f..2e683e7c475fce6556108a2e536308d7a90e36d0 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Add start_hour and end_hour options to the select_hour helper. *Evan Tann* + * Raises an ArgumentError when the first argument in `form_for` contain `nil` or is empty. diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 659aacf6d7631470d2a354675087ce4fcbfdfd51..dea2aa69dd1a6b55bfaafea6fbd75d51154b8308 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -427,6 +427,9 @@ def select_date(date = Date.current, options = {}, html_options = {}) # # Generate a time select field with hours in the AM/PM format # select_time(my_time, :ampm => true) # + # # Generates a time select field with hours that range from 2 to 14 + # select_time(my_time, :start_hour => 2, :end_hour => 14) + # # # Generates a time select with a custom prompt. Use :prompt to true for generic prompts. # select_time(my_time, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) # select_time(my_time, :prompt => {:hour => true}) # generic prompt for hours @@ -504,6 +507,9 @@ def select_minute(datetime, options = {}, html_options = {}) # # # Generate a select field for hours in the AM/PM format # select_hour(my_time, :ampm => true) + # + # # Generates a select field that includes options for hours from 2 to 14. + # select_hour(my_time, :start_hour => 2, :end_hour => 14) def select_hour(datetime, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_hour end @@ -734,7 +740,11 @@ def select_hour if @options[:use_hidden] || @options[:discard_hour] build_hidden(:hour, hour) else - build_options_and_select(:hour, hour, :end => 23, :ampm => @options[:ampm]) + options = {} + options[:ampm] = @options[:ampm] || false + options[:start] = @options[:start_hour] || 0 + options[:end] = @options[:end_hour] || 23 + build_options_and_select(:hour, hour, options) end end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index ff85a675a2790094c1a7db060e1b20dd0d702c99..c13878af989b900eadee48dd726bb5118bc591d5 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1243,6 +1243,35 @@ def test_select_datetime_with_custom_prompt :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year', :hour => 'Choose hour', :minute => 'Choose minute'}) end + def test_select_datetime_with_custom_hours + expected = %(\n" + + expected << %(\n" + + expected << %(\n" + + expected << " — " + + expected << %(\n" + + expected << " : " + + expected << %(\n" + + assert_dom_equal expected, select_datetime(Time.mktime(2003, 8, 16, 8, 4, 18), :start_year => 2003, :end_year => 2005, :start_hour => 1, :end_hour => 9, :prefix => "date[first]", + :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year', :hour => 'Choose hour', :minute => 'Choose minute'}) + end + def test_select_datetime_with_hidden expected = %(\n) expected << %(\n)