Skip to content

Commit

Permalink
Add fieldset_tag for generating fieldsets, closes rails#9477. [djanow…
Browse files Browse the repository at this point in the history
…ski]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7413 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Sep 6, 2007
1 parent 8a9f43e commit 0e6c8e5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* Add fieldset_tag for generating fieldsets, closes #9477. [djanowski]

* Allow additional parameters to be passed to named route helpers when using positional arguments. Closes #8930 [ian.w.white@gmail.com]

* Make render :partial work with a :collection of Hashes, previously this wasn't possible due to backwards compatibility restrictions. [lifofifo]
Expand Down
22 changes: 22 additions & 0 deletions actionpack/lib/action_view/helpers/form_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,28 @@ def submit_tag(value = "Save changes", options = {})
def image_submit_tag(source, options = {})
tag :input, { "type" => "image", "src" => image_path(source) }.update(options.stringify_keys)
end

# Creates a field set for grouping HTML form elements.
#
# <tt>legend</tt> will become the fieldset's title (optional as per W3C).
#
# === Examples
# <% fieldset_tag do %>
# <p><%= text_field_tag 'name' %></p>
# <% end %>
# # => <fieldset><p><input id="name" name="name" type="text" /></p></fieldset>
#
# <% fieldset_tag 'Your details' do %>
# <p><%= text_field_tag 'name' %></p>
# <% end %>
# # => <fieldset><legend>Your details</legend><p><input id="name" name="name" type="text" /></p></fieldset>
def fieldset_tag(legend = nil, &block)
content = capture(&block)
concat(tag(:fieldset, {}, true), block.binding)
concat(content_tag(:legend, legend), block.binding) unless legend.blank?
concat(content, block.binding)
concat("</fieldset>", block.binding)
end

private
def html_options_for_form(url_for_options, options, *parameters_for_url)
Expand Down
20 changes: 20 additions & 0 deletions actionpack/test/template/form_tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,24 @@ def test_submit_tag
def test_pass
assert_equal 1, 1
end

def test_fieldset_tag
_erbout = ''
fieldset_tag("Your details") { _erbout.concat "Hello world!" }

expected = %(<fieldset><legend>Your details</legend>Hello world!</fieldset>)
assert_dom_equal expected, _erbout

_erbout = ''
fieldset_tag { _erbout.concat "Hello world!" }

expected = %(<fieldset>Hello world!</fieldset>)
assert_dom_equal expected, _erbout

_erbout = ''
fieldset_tag('') { _erbout.concat "Hello world!" }

expected = %(<fieldset>Hello world!</fieldset>)
assert_dom_equal expected, _erbout
end
end

0 comments on commit 0e6c8e5

Please sign in to comment.