From b141624abbd1be6aa9836708fe4c20c03af5ab3b Mon Sep 17 00:00:00 2001
From: Alastair Brunton <info@simplyexcited.co.uk>
Date: Fri, 8 Aug 2008 15:55:50 +0200
Subject: Added image_submit_tag confirm option [status:committed #784]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
---
 actionpack/lib/action_view/helpers/form_tag_helper.rb | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'actionpack/lib')

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
 
-- 
cgit v1.2.3