Permalink
Browse files

Make type="submit" the default for button_tag helper

"submit" is the default value of the <button> element's type attribute
according to the HTML 4.01 and the HTML5 draft specs, so if button_tag
is going to have a default, type="submit" is a more sensible choice than
type="button".

http://www.w3.org/TR/html401/interact/forms.html#adef-type-BUTTON
http://dev.w3.org/html5/spec/the-button-element.html#attr-button-type

Signed-off-by: Santiago Pastorino and Emilio Tagua <santiago+emilioe@wyeworks.com>
  • Loading branch information...
1 parent e8c8707 commit 03749d6c88ae8312dc959b7683851dbf8c969326 @tomstuart tomstuart committed with Santiago Pastorino and Emilio Tagua Feb 12, 2011
@@ -431,16 +431,16 @@ def submit_tag(value = "Save changes", options = {})
#
# ==== 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 @@ def button_tag(label = "Button", options = {})
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
@@ -387,7 +387,7 @@ def test_submit_tag_with_confirmation_and_with_disable_with
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 @@ def test_button_tag_with_submit_type
)
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>),

0 comments on commit 03749d6

Please sign in to comment.