Skip to content

Commit

Permalink
Merge pull request #50241 from seanpdoyle/fieldset-tag-alias
Browse files Browse the repository at this point in the history
Alias `field_set_tag` helper to `fieldset_tag`
  • Loading branch information
byroot committed Dec 2, 2023
2 parents 9ec451f + c5ae44d commit 90daef6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions actionview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Alias `field_set_tag` helper to `fieldset_tag` to match `<fieldset>` element

*Sean Doyle*

* Deprecate passing content to void elements when using `tag.br` type tag builders.

*Hartley McGuire*
Expand Down
10 changes: 6 additions & 4 deletions actionview/lib/action_view/helpers/form_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,13 @@ def image_submit_tag(source, options = {})
# <% end %>
# # => <fieldset class="format"><p><input id="name" name="name" type="text" /></p></fieldset>
def field_set_tag(legend = nil, options = nil, &block)
output = tag(:fieldset, options, true)
output.safe_concat(content_tag("legend", legend)) unless legend.blank?
output.concat(capture(&block)) if block_given?
output.safe_concat("</fieldset>")
content = []
content << content_tag("legend", legend) unless legend.blank?
content << capture(&block) if block_given?

content_tag(:fieldset, safe_join(content), options)
end
alias_method :fieldset_tag, :field_set_tag

# Creates a text field of type "color".
#
Expand Down
5 changes: 5 additions & 0 deletions actionview/test/template/form_tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,11 @@ def test_field_set_tag_in_erb
expected = %(<fieldset class="format">Hello world!</fieldset>)
assert_dom_equal expected, output_buffer

output_buffer = render_erb("<%= fieldset_tag('', :class => 'format') do %>Hello world!<% end %>")

expected = %(<fieldset class="format">Hello world!</fieldset>)
assert_dom_equal expected, output_buffer

output_buffer = render_erb("<%= field_set_tag %>")

expected = %(<fieldset></fieldset>)
Expand Down

0 comments on commit 90daef6

Please sign in to comment.