aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb10
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb9
2 files changed, 12 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index d6b74974e9..c4a5a683d0 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -431,16 +431,16 @@ module ActionView
#
# ==== Examples
# button_tag
- # # => <button name="button" type="button">Button</button>
+ # # => <button name="button" type="submit">Button</button>
#
- # button_tag "<strong>Ask me!</strong>"
+ # button_tag "<strong>Ask me!</strong>", :type => 'button'
# # => <button name="button" type="button">
# <strong>Ask me!</strong>
# </button>
#
# button_tag "Checkout", :disable_with => "Please wait..."
# # => <button data-disable-with="Please wait..." name="button"
- # type="button">Checkout</button>
+ # type="submit">Checkout</button>
#
def button_tag(label = "Button", options = {})
options.stringify_keys!
@@ -453,9 +453,7 @@ module ActionView
options["data-confirm"] = confirm
end
- ["type", "name"].each do |option|
- options[option] = "button" unless options[option]
- end
+ options.reverse_merge! 'name' => 'button', 'type' => 'submit'
content_tag :button, label, { "type" => options.delete("type") }.update(options)
end
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 4a584b8db8..c22af258c3 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -387,7 +387,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_button_tag
assert_dom_equal(
- %(<button name="button" type="button">Button</button>),
+ %(<button name="button" type="submit">Button</button>),
button_tag
)
end
@@ -399,6 +399,13 @@ class FormTagHelperTest < ActionView::TestCase
)
end
+ def test_button_tag_with_button_type
+ assert_dom_equal(
+ %(<button name="button" type="button">Button</button>),
+ button_tag("Button", :type => "button")
+ )
+ end
+
def test_button_tag_with_reset_type
assert_dom_equal(
%(<button name="button" type="reset">Reset</button>),