Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14255 from prikha/master

Fixes #14254 ActionView button_tag helper default options values issue.
  • Loading branch information...
commit 87d520be16bdfdd1989b51d704800b22f3bb334b 2 parents ffcc617 + e447ed6
@chancancode chancancode authored
View
19 actionview/lib/action_view/helpers/form_tag_helper.rb
@@ -469,13 +469,22 @@ def submit_tag(value = "Save changes", options = {})
# # => <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.
View
5 actionview/test/template/form_tag_helper_test.rb
@@ -476,6 +476,11 @@ def test_button_tag_with_block_and_options
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>),
Please sign in to comment.
Something went wrong with that request. Please try again.