diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index c8773c91793bb..4bed35aca751e 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,8 @@ ## Rails 4.0.0 (unreleased) ## +* `date_select` helper accepts :with_css_classes => true to add css classes similar with type + of generated select tags. *Pavel Nikitin* + * `assert_template` can be used to assert on the same template with different locals Fix #3675 diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 387dfeab172ff..5464437e42936 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -196,6 +196,8 @@ def time_ago_in_words(from_time, include_seconds_or_options = {}) # for :year, :month, :day, :hour, :minute and :second. # Setting this option prepends a select option with a generic prompt (Day, Month, Year, Hour, Minute, Seconds) # or the given prompt string. + # * :with_css_classes - Set to true if you want assign different styles for 'select' tags. This option + # automatically set classes 'year', 'month', 'day', 'hour', 'minute' and 'second' for your 'select' tags. # # If anything is passed in the +html_options+ hash it will be applied to every select tag in the set. # @@ -937,6 +939,7 @@ def build_select(type, select_options_as_html) :name => input_name_from_type(type) }.merge!(@html_options) select_options[:disabled] = 'disabled' if @options[:disabled] + select_options[:class] = type if @options[:with_css_classes] select_html = "\n" select_html << content_tag(:option, '', :value => '') + "\n" if @options[:include_blank] diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index a4da7cd4b00f3..8bd8eff3c0150 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1007,6 +1007,22 @@ def test_select_date_with_hidden assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), { :date_separator => " / ", :prefix => "date[first]", :use_hidden => true }) end + def test_select_date_with_css_classes_option + expected = %(\n" + + expected << %(\n" + + expected << %(\n" + + assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), {:start_year => 2003, :end_year => 2005, :prefix => "date[first]", :with_css_classes => true}) + end + def test_select_datetime expected = %(