From 00b4a039b1b645bc6e221ea85280364da8bfb1f4 Mon Sep 17 00:00:00 2001 From: Andrei Bocan Date: Fri, 19 Nov 2010 20:25:21 +0200 Subject: [PATCH] Allow customization of form class for button_to --- actionpack/lib/action_view/helpers/url_helper.rb | 16 +++++++++++++--- actionpack/test/template/url_helper_test.rb | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index c23315b..cfa88c9 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -253,8 +253,9 @@ module ActionView # using the +link_to+ method with the :method modifier as described in # the +link_to+ documentation. # - # The generated form element has a class name of button_to - # to allow styling of the form itself and its children. You can control + # By default, the generated form element has a class name of button_to + # to allow styling of the form itself and its children. This can be changed + # using the :form_class modifier within +html_options+. You can control # the form submission and input element behavior using +html_options+. # This method accepts the :method and :confirm modifiers # described in the +link_to+ documentation. If no :method modifier @@ -275,6 +276,8 @@ module ActionView # processed normally, otherwise no action is taken. # * :remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the # submit behaviour. By default this behaviour is an ajax submit. + # * :form_class - This controls the class of the form within which the submit button will + # be placed # # ==== Examples # <%= button_to "New", :action => "new" %> @@ -283,6 +286,12 @@ module ActionView # # " # # + # <%= button_to "New", :action => "new", :form_class => "new-thing" %> + # # => "
+ # #
+ # #
" + # + # # <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, # :confirm => "Are you sure?", :method => :delete %> # # => "
@@ -312,6 +321,7 @@ module ActionView end form_method = method.to_s == 'get' ? 'get' : 'post' + form_class = html_options.delete('form_class') || 'button_to' remote = html_options.delete('remote') @@ -327,7 +337,7 @@ module ActionView html_options.merge!("type" => "submit", "value" => name) - ("
" + + ("
" + method_tag + tag("input", html_options) + request_token_tag + "
").html_safe end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 4a8cea3..4223231 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -50,6 +50,10 @@ class UrlHelperTest < ActiveSupport::TestCase assert_dom_equal "
", button_to("Hello", "http://www.example.com") end + def test_button_to_with_form_class + assert_dom_equal "
", button_to("Hello", "http://www.example.com", :form_class => 'custom-class') + end + def test_button_to_with_query assert_dom_equal "
", button_to("Hello", "http://www.example.com/q1=v1&q2=v2") end -- 1.7.0