From 7c0e5ef916220d5fdc078817e3eb04b5f7896217 Mon Sep 17 00:00:00 2001 From: Alastair Brunton Date: Fri, 8 Aug 2008 15:55:50 +0200 Subject: [PATCH] image_submit_tag confirm option addition --- .../lib/action_view/helpers/form_tag_helper.rb | 10 ++++++++++ actionpack/test/template/form_tag_helper_test.rb | 7 +++++++ 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index e8ca02d..9e3ea6a 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -374,6 +374,9 @@ module ActionView # source is passed to AssetTagHelper#image_path # # ==== Options + # * :confirm => 'question?' - 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. # * :disabled - If set to true, the user will not be able to use this input. # * Any other key creates standard HTML options for the tag. # @@ -390,6 +393,13 @@ module ActionView # image_submit_tag("agree.png", :disabled => true, :class => "agree-disagree-button") # # => 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 9b41ff8..f1b1b0f 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( + %(), + image_submit_tag("save.gif", :confirm => "Are you sure?") + ) + end def test_pass assert_equal 1, 1 -- 1.5.2.5