Skip to content

Commit

Permalink
Allow date helpers to ignore date hidden field tags. [#503 state:reso…
Browse files Browse the repository at this point in the history
…lved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
miloops authored and lifo committed Jul 4, 2008
1 parent 1a47892 commit 570f5aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions actionpack/lib/action_view/helpers/date_helper.rb
Expand Up @@ -159,7 +159,10 @@ def date_select(object_name, method, options = {}, html_options = {})
# Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified
# time-based attribute (identified by +method+) on an object assigned to the template (identified by +object+).
# You can include the seconds with <tt>:include_seconds</tt>.
#
#
# This method will also generate 3 input hidden tags, for the actual year, month and day unless the option
# <tt>:ignore_date</tt> is set to +true+.
#
# If anything is passed in the html_options hash it will be applied to every select tag in the set.
#
# ==== Examples
Expand Down Expand Up @@ -655,7 +658,7 @@ def date_or_time_select(options, html_options = {})
order.reverse.each do |param|
# Send hidden fields for discarded elements once output has started
# This ensures AR can reconstruct valid dates using ParseDate
next if discard[param] && date_or_time_select.empty?
next if discard[param] && (date_or_time_select.empty? || options[:ignore_date])

date_or_time_select.insert(0, self.send("select_#{param}", datetime, options_with_prefix(position[param], options.merge(:use_hidden => discard[param])), html_options))
date_or_time_select.insert(0,
Expand Down
15 changes: 15 additions & 0 deletions actionpack/test/template/date_helper_test.rb
Expand Up @@ -1198,6 +1198,21 @@ def test_time_select
assert_dom_equal expected, time_select("post", "written_on")
end

def test_time_select_without_date_hidden_fields
@post = Post.new
@post.written_on = Time.local(2004, 6, 15, 15, 16, 35)

expected = %(<select id="post_written_on_4i" name="post[written_on(4i)]">\n)
0.upto(23) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 15}>#{leading_zero_on_single_digits(i)}</option>\n) }
expected << "</select>\n"
expected << " : "
expected << %(<select id="post_written_on_5i" name="post[written_on(5i)]">\n)
0.upto(59) { |i| expected << %(<option value="#{leading_zero_on_single_digits(i)}"#{' selected="selected"' if i == 16}>#{leading_zero_on_single_digits(i)}</option>\n) }
expected << "</select>\n"

assert_dom_equal expected, time_select("post", "written_on", :ignore_date => true)
end

def test_time_select_with_seconds
@post = Post.new
@post.written_on = Time.local(2004, 6, 15, 15, 16, 35)
Expand Down

0 comments on commit 570f5aa

Please sign in to comment.