Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow empty fieldsets to be created without a block. #5234

Merged
merged 1 commit into from

3 participants

@benpickles

Without this I have to use a superfluous empty block:

<%= field_set_tag 'Legend!' do %>
<% end %>
@drogus
Collaborator

Just curious, could you provide any good case when I would want to have an empty fieldset?

@benpickles

In our case we're populating the empty fieldset on the client-side - but it's also about minimising surprises: I was surprised to get a LocalJumpError when I didn't include a block.

@drogus
Collaborator

Makes sense, it's always a good practice to check for a block anyway.

@drogus drogus merged commit 9078dba into from
@homakov

<%= field_set_tag('Legend!'){} %>
looks lighter btw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 1, 2012
  1. @benpickles
This page is out of date. Refresh to see the latest.
View
3  actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -525,10 +525,9 @@ 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)
- content = capture(&block)
output = tag(:fieldset, options, true)
output.safe_concat(content_tag(:legend, legend)) unless legend.blank?
- output.concat(content)
+ output.concat(capture(&block)) if block_given?
output.safe_concat("</fieldset>")
end
View
10 actionpack/test/template/form_tag_helper_test.rb
@@ -513,6 +513,16 @@ def test_field_set_tag_in_erb
expected = %(<fieldset class="format">Hello world!</fieldset>)
assert_dom_equal expected, output_buffer
+
+ output_buffer = render_erb("<%= field_set_tag %>")
+
+ expected = %(<fieldset></fieldset>)
+ assert_dom_equal expected, output_buffer
+
+ output_buffer = render_erb("<%= field_set_tag('You legend!') %>")
+
+ expected = %(<fieldset><legend>You legend!</legend></fieldset>)
+ assert_dom_equal expected, output_buffer
end
def test_text_area_tag_options_symbolize_keys_side_effects
Something went wrong with that request. Please try again.