aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-09-06 05:53:29 +0000
committerMichael Koziarski <michael@koziarski.com>2007-09-06 05:53:29 +0000
commit0e6c8e5f6c168b9d376122f730c604d3758f4b04 (patch)
treefdb197bdbd56852d20203b0f9d64053dc9b4582d
parent8a9f43ecbb99f470cc8720c09a1c9480abdc845e (diff)
downloadrails-0e6c8e5f6c168b9d376122f730c604d3758f4b04.tar.gz
rails-0e6c8e5f6c168b9d376122f730c604d3758f4b04.tar.bz2
rails-0e6c8e5f6c168b9d376122f730c604d3758f4b04.zip
Add fieldset_tag for generating fieldsets, closes #9477. [djanowski]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7413 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb22
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb20
3 files changed, 44 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 233a3661a5..50af35eb14 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index c3cabb10f7..39e508f433 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -363,6 +363,28 @@ module ActionView
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)
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 5e89cbbd54..c2cdd7666c 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -157,4 +157,24 @@ class FormTagHelperTest < Test::Unit::TestCase
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