Permalink
Browse files

Merge pull request #6631 from yuki24/use_block_in_button_helper

Accept a block in FormHelper#button
  • Loading branch information...
2 parents fedb0e2 + 0ec88cd commit 76830e110a73d6db0dafd42fc960686637cbfc7b @josevalim josevalim committed Jun 5, 2012
Showing with 18 additions and 3 deletions.
  1. +13 −2 actionpack/lib/action_view/helpers/form_helper.rb
  2. +5 −1 actionpack/test/template/form_helper_test.rb
View
15 actionpack/lib/action_view/helpers/form_helper.rb
@@ -1311,10 +1311,21 @@ def submit(value=nil, options={})
# post:
# create: "Add %{model}"
#
- def button(value=nil, options={})
+ # ==== Examples
+ # button("Create a post")
+ # # => <button name='button' type='submit'>Create post</button>
+ #
+ # button do
+ # content_tag(:strong, 'Ask me!')
+ # end
+ # # => <button name='button' type='submit'>
+ # # <strong>Ask me!</strong>
+ # # </button>
+ #
+ def button(value = nil, options = {}, &block)
value, options = nil, value if value.is_a?(Hash)
value ||= submit_default_value
- @template.button_tag(value, options)
+ @template.button_tag(value, options, &block)
end
def emitted_hidden_id?
View
6 actionpack/test/template/form_helper_test.rb
@@ -1054,6 +1054,9 @@ def test_form_for
concat f.check_box(:secret)
concat f.submit('Create post')
concat f.button('Create post')
+ concat f.button {
+ concat content_tag(:span, 'Create post')
+ }
end
expected = whole_form("/posts/123", "create-post" , "edit_post", :method => 'patch') do
@@ -1063,7 +1066,8 @@ def test_form_for
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
"<input name='commit' type='submit' value='Create post' />" +
- "<button name='button' type='submit'>Create post</button>"
+ "<button name='button' type='submit'>Create post</button>" +
+ "<button name='button' type='submit'><span>Create post</span></button>"
end
assert_dom_equal expected, output_buffer

0 comments on commit 76830e1

Please sign in to comment.