Alias field_set_tag
helper to fieldset_tag
The [field_set_tag][] renders a `<fieldset>` element. At times, the desire to render a `fieldset` results in calling `fieldset_tag`, only to be surprised by a `NoMethodError`. Originally, the method's name was `fieldset_tag` helper (defined in [0e6c8e5][] in 2007), but was renamed in [73c7083][] (3 days later). This commit aliases `field_set_tag` to `fieldset_tag` so that both are available. Additionally, defines the method so that it utilizes the [content_tag][] so that it isn't responsible for manually managing the closing (`</fieldset>`) of the opening `<fieldset>` tag. [field_set_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-field_set_tag [0e6c8e5]:0e6c8e5f6c
[73c7083]:73c7083651
[content_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag
This commit is contained in:
parent
b3b230c08e
commit
c5ae44d659
@ -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*
|
||||
|
@ -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".
|
||||
#
|
||||
|
@ -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>)
|
||||
|
Loading…
Reference in New Issue
Block a user