GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Allow date helpers to ignore date hidden field tags. [#503 state:resolved]


Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
miloops (author)
Tue Jul 01 07:08:25 -0700 2008
lifo (committer)
Thu Jul 03 17:06:22 -0700 2008
commit  570f5aad663fa3113772cf56306862829babc739
tree    fd97d993462725d336500c094450866e1bfb6761
parent  1a478923dc909bf7b6aea4f2ad49cbeee6dea259
...
159
160
161
162
 
 
 
 
163
164
165
...
655
656
657
658
 
659
660
661
...
159
160
161
 
162
163
164
165
166
167
168
...
658
659
660
 
661
662
663
664
0
@@ -159,7 +159,10 @@ module ActionView
0
       # Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified
0
       # time-based attribute (identified by +method+) on an object assigned to the template (identified by +object+).
0
       # You can include the seconds with <tt>:include_seconds</tt>.
0
- #
0
+ #
0
+ # This method will also generate 3 input hidden tags, for the actual year, month and day unless the option
0
+ # <tt>:ignore_date</tt> is set to +true+.
0
+ #
0
       # If anything is passed in the html_options hash it will be applied to every select tag in the set.
0
       #
0
       # ==== Examples
0
@@ -655,7 +658,7 @@ module ActionView
0
           order.reverse.each do |param|
0
             # Send hidden fields for discarded elements once output has started
0
             # This ensures AR can reconstruct valid dates using ParseDate
0
- next if discard[param] && date_or_time_select.empty?
0
+ next if discard[param] && (date_or_time_select.empty? || options[:ignore_date])
0
 
0
             date_or_time_select.insert(0, self.send("select_#{param}", datetime, options_with_prefix(position[param], options.merge(:use_hidden => discard[param])), html_options))
0
             date_or_time_select.insert(0,
...
1198
1199
1200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1201
1202
1203
...
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
0
@@ -1198,6 +1198,21 @@ class DateHelperTest < ActionView::TestCase
0
     assert_dom_equal expected, time_select("post", "written_on")
0
   end
0
 
0
+ def test_time_select_without_date_hidden_fields
0
+ @post = Post.new
0
+ @post.written_on = Time.local(2004, 6, 15, 15, 16, 35)
0
+
0
+ expected = %(<select id="post_written_on_4i" name="post[written_on(4i)]">\n)
0
+ 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) }
0
+ expected << "</select>\n"
0
+ expected << " : "
0
+ expected << %(<select id="post_written_on_5i" name="post[written_on(5i)]">\n)
0
+ 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) }
0
+ expected << "</select>\n"
0
+
0
+ assert_dom_equal expected, time_select("post", "written_on", :ignore_date => true)
0
+ end
0
+
0
   def test_time_select_with_seconds
0
     @post = Post.new
0
     @post.written_on = Time.local(2004, 6, 15, 15, 16, 35)

Comments

    No one has commented yet.