public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added image_submit_tag confirm option [status:committed #784]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
pyrat (author)
Fri Aug 08 06:55:50 -0700 2008
dhh (committer)
Tue Sep 09 22:13:35 -0700 2008
commit  b141624abbd1be6aa9836708fe4c20c03af5ab3b
tree    101054db556e9941b55e2bc9fc111516344b4033
parent  184cf27b1244734a33833cf2cb9b8062e9ee8a63
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *Edge*
0
 
0
+* Added FormTagHelper#image_submit_tag confirm option #784 [Alastair Brunton]
0
+
0
 * Fixed FormTagHelper#submit_tag with :disable_with option wouldn't submit the button's value when was clicked #633 [Jose Fernandez]
0
 
0
 * Stopped logging template compiles as it only clogs up the log [DHH]
...
371
372
373
 
 
 
374
375
376
...
387
388
389
 
 
 
 
 
 
 
390
391
392
...
371
372
373
374
375
376
377
378
379
...
390
391
392
393
394
395
396
397
398
399
400
401
402
0
@@ -371,6 +371,9 @@ module ActionView
0
       # <tt>source</tt> is passed to AssetTagHelper#image_path
0
       #
0
       # ==== Options
0
+      # * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
0
+      #   prompt with the question specified. If the user accepts, the form is
0
+      #   processed normally, otherwise no action is taken.
0
       # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
0
       # * Any other key creates standard HTML options for the tag.
0
       #
0
@@ -387,6 +390,13 @@ module ActionView
0
       #   image_submit_tag("agree.png", :disabled => true, :class => "agree-disagree-button")
0
       #   # => <input class="agree-disagree-button" disabled="disabled" src="/images/agree.png" type="image" />
0
       def image_submit_tag(source, options = {})
0
+        options.stringify_keys!
0
+
0
+        if confirm = options.delete("confirm")
0
+          options["onclick"] ||= ''
0
+          options["onclick"] += "return #{confirm_javascript_function(confirm)};"
0
+        end
0
+
0
         tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys)
0
       end
0
 
...
241
242
243
 
 
 
 
 
 
 
244
245
246
...
241
242
243
244
245
246
247
248
249
250
251
252
253
0
@@ -241,6 +241,13 @@ class FormTagHelperTest < ActionView::TestCase
0
       submit_tag("Save", :confirm => "Are you sure?")
0
     )
0
   end
0
+  
0
+  def test_image_submit_tag_with_confirmation
0
+    assert_dom_equal(
0
+      %(<input type="image" src="/images/save.gif" onclick="return confirm('Are you sure?');"/>),
0
+      image_submit_tag("save.gif", :confirm => "Are you sure?")
0
+    )
0
+  end
0
 
0
   def test_pass
0
     assert_equal 1, 1

Comments