提交 60bbbce7 编写于 作者: S Sergey Prikhodko

fixes default attributes for button_tag

上级 1d298bd6
......@@ -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>),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册