aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlastair Brunton <info@simplyexcited.co.uk>2008-08-08 15:55:50 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-09-10 00:13:35 -0500
commitb141624abbd1be6aa9836708fe4c20c03af5ab3b (patch)
tree101054db556e9941b55e2bc9fc111516344b4033
parent184cf27b1244734a33833cf2cb9b8062e9ee8a63 (diff)
downloadrails-b141624abbd1be6aa9836708fe4c20c03af5ab3b.tar.gz
rails-b141624abbd1be6aa9836708fe4c20c03af5ab3b.tar.bz2
rails-b141624abbd1be6aa9836708fe4c20c03af5ab3b.zip
Added image_submit_tag confirm option [status:committed #784]
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb10
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb7
3 files changed, 19 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index adc4dec229..3743e3e8fe 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*
+* Added FormTagHelper#image_submit_tag confirm option #784 [Alastair Brunton]
+
* Fixed FormTagHelper#submit_tag with :disable_with option wouldn't submit the button's value when was clicked #633 [Jose Fernandez]
* Stopped logging template compiles as it only clogs up the log [DHH]
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index fe7e174c4d..294c22521e 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -371,6 +371,9 @@ module ActionView
# <tt>source</tt> is passed to AssetTagHelper#image_path
#
# ==== Options
+ # * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
+ # prompt with the question specified. If the user accepts, the form is
+ # processed normally, otherwise no action is taken.
# * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
# * Any other key creates standard HTML options for the tag.
#
@@ -387,6 +390,13 @@ module ActionView
# image_submit_tag("agree.png", :disabled => true, :class => "agree-disagree-button")
# # => <input class="agree-disagree-button" disabled="disabled" src="/images/agree.png" type="image" />
def image_submit_tag(source, options = {})
+ options.stringify_keys!
+
+ if confirm = options.delete("confirm")
+ options["onclick"] ||= ''
+ options["onclick"] += "return #{confirm_javascript_function(confirm)};"
+ end
+
tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys)
end
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 15e84564be..6473d011d5 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -241,6 +241,13 @@ class FormTagHelperTest < ActionView::TestCase
submit_tag("Save", :confirm => "Are you sure?")
)
end
+
+ def test_image_submit_tag_with_confirmation
+ assert_dom_equal(
+ %(<input type="image" src="/images/save.gif" onclick="return confirm('Are you sure?');"/>),
+ image_submit_tag("save.gif", :confirm => "Are you sure?")
+ )
+ end
def test_pass
assert_equal 1, 1