aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-03-04 02:51:58 -0800
committerGodfrey Chan <godfreykfc@gmail.com>2014-03-04 02:51:58 -0800
commit87d520be16bdfdd1989b51d704800b22f3bb334b (patch)
tree838fb8923af30f8cb08407090c2a37bedba66dc5
parentffcc6172b4d40ca7c8b02fd298c679b5bcf5787b (diff)
parente447ed6902e0134128728db7baaa48cdf74dc788 (diff)
downloadrails-87d520be16bdfdd1989b51d704800b22f3bb334b.tar.gz
rails-87d520be16bdfdd1989b51d704800b22f3bb334b.tar.bz2
rails-87d520be16bdfdd1989b51d704800b22f3bb334b.zip
Merge pull request #14255 from prikha/master
Fixes #14254 ActionView button_tag helper default options values issue.
-rw-r--r--actionview/lib/action_view/helpers/form_tag_helper.rb19
-rw-r--r--actionview/test/template/form_tag_helper_test.rb5
2 files changed, 19 insertions, 5 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..961d01eff4 100644
--- a/actionview/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/form_tag_helper.rb
@@ -469,13 +469,22 @@ 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
+ default_options = { 'name' => 'button', 'type' => 'submit' }
- options.reverse_merge! 'name' => 'button', 'type' => 'submit'
+ if content_or_options.is_a? Hash
+ options = content_or_options
+ else
+ options ||= {}
+ end
- content_tag :button, content_or_options || 'Button', options, &block
+ options = options.stringify_keys
+ options = options.reverse_merge default_options
+
+ if block_given?
+ content_tag :button, options, &block
+ else
+ content_tag :button, content_or_options || 'Button', options
+ end
end
# Displays an image which when clicked will submit the form.
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>),