Permalink
Browse files

fixes default attributes for button_tag

  • Loading branch information...
prikha committed Mar 3, 2014
1 parent 1d298bd commit 60bbbce7a302c18d3ab8b7450f94cabc9bbea835
@@ -469,13 +469,13 @@ 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
-
- 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 @@ def form_tag_in_block(html_options, &block)
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
@@ -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>),

0 comments on commit 60bbbce

Please sign in to comment.