1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add options to field_set_tag

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1116 state:committed]
This commit is contained in:
Andrew Kaspick 2008-09-25 21:44:34 -05:00 committed by Michael Koziarski
parent 28bf2fa038
commit 8c105ee0c8
2 changed files with 14 additions and 2 deletions

View file

@ -403,6 +403,7 @@ module ActionView
# Creates a field set for grouping HTML form elements. # Creates a field set for grouping HTML form elements.
# #
# <tt>legend</tt> will become the fieldset's title (optional as per W3C). # <tt>legend</tt> will become the fieldset's title (optional as per W3C).
# <tt>options</tt> accept the same values as tag.
# #
# === Examples # === Examples
# <% field_set_tag do %> # <% field_set_tag do %>
@ -414,9 +415,14 @@ module ActionView
# <p><%= text_field_tag 'name' %></p> # <p><%= text_field_tag 'name' %></p>
# <% end %> # <% end %>
# # => <fieldset><legend>Your details</legend><p><input id="name" name="name" type="text" /></p></fieldset> # # => <fieldset><legend>Your details</legend><p><input id="name" name="name" type="text" /></p></fieldset>
def field_set_tag(legend = nil, &block) #
# <% field_set_tag nil, :class => 'format' do %>
# <p><%= text_field_tag 'name' %></p>
# <% 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) content = capture(&block)
concat(tag(:fieldset, {}, true)) concat(tag(:fieldset, options, true))
concat(content_tag(:legend, legend)) unless legend.blank? concat(content_tag(:legend, legend)) unless legend.blank?
concat(content) concat(content)
concat("</fieldset>") concat("</fieldset>")

View file

@ -271,6 +271,12 @@ class FormTagHelperTest < ActionView::TestCase
expected = %(<fieldset>Hello world!</fieldset>) expected = %(<fieldset>Hello world!</fieldset>)
assert_dom_equal expected, output_buffer assert_dom_equal expected, output_buffer
self.output_buffer = ''
field_set_tag('', :class => 'format') { concat "Hello world!" }
expected = %(<fieldset class="format">Hello world!</fieldset>)
assert_dom_equal expected, output_buffer
end end
def protect_against_forgery? def protect_against_forgery?