aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prikhodko <prikha@gmail.com>2014-03-03 12:23:51 +0400
committerSergey Prikhodko <prikha@gmail.com>2014-03-03 12:23:51 +0400
commit60bbbce7a302c18d3ab8b7450f94cabc9bbea835 (patch)
tree4c874755d234ad75d368e62d00f6b6058eba0c07
parent1d298bd6217d6c0feb3aa698d65289b92b11ab8d (diff)
downloadrails-60bbbce7a302c18d3ab8b7450f94cabc9bbea835.tar.gz
rails-60bbbce7a302c18d3ab8b7450f94cabc9bbea835.tar.bz2
rails-60bbbce7a302c18d3ab8b7450f94cabc9bbea835.zip
fixes default attributes for button_tag
-rw-r--r--actionview/lib/action_view/helpers/form_tag_helper.rb20
-rw-r--r--actionview/test/template/form_tag_helper_test.rb5
2 files changed, 18 insertions, 7 deletions
diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb
index 80f066b3be..bb38ae8555 100644
--- a/actionview/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/form_tag_helper.rb
@@ -469,13 +469,13 @@ module ActionView
# # => <button data-disable-with="Please wait..." name="button" type="submit">Checkout</button>
#
def button_tag(content_or_options = nil, options = nil, &block)
- options = content_or_options if block_given? && content_or_options.is_a?(Hash)
- options ||= {}
- options = options.stringify_keys
-
- options.reverse_merge! 'name' => 'button', 'type' => 'submit'
-
- content_tag :button, content_or_options || 'Button', options, &block
+ if block_given? && content_or_options.is_a?(Hash)
+ options = button_tag_options_with_defaults(content_or_options)
+ content_tag :button, options, &block
+ else
+ options = button_tag_options_with_defaults(options)
+ content_tag :button, content_or_options || 'Button', options
+ end
end
# Displays an image which when clicked will submit the form.
@@ -741,6 +741,12 @@ module ActionView
def sanitize_to_id(name)
name.to_s.delete(']').gsub(/[^-a-zA-Z0-9:.]/, "_")
end
+
+ def button_tag_options_with_defaults(options = {})
+ default_options = { 'name' => 'button', 'type' => 'submit' }
+ options.stringify_keys!
+ options.reverse_merge! default_options
+ end
end
end
end
diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb
index 0d5831dc6f..cf824e2733 100644
--- a/actionview/test/template/form_tag_helper_test.rb
+++ b/actionview/test/template/form_tag_helper_test.rb
@@ -476,6 +476,11 @@ class FormTagHelperTest < ActionView::TestCase
assert_dom_equal('<button name="temptation" type="button"><strong>Do not press me</strong></button>', output)
end
+ def test_button_tag_defaults_with_block_and_options
+ output = button_tag(:name => 'temptation', :value => 'within') { content_tag(:strong, 'Do not press me') }
+ assert_dom_equal('<button name="temptation" value="within" type="submit" ><strong>Do not press me</strong></button>', output)
+ end
+
def test_button_tag_with_confirmation
assert_dom_equal(
%(<button name="button" type="submit" data-confirm="Are you sure?">Save</button>),