diff options
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 16 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 3 |
2 files changed, 18 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index ba5fc39537..78123a9d87 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -31,12 +31,20 @@ module ActionView "</form>" end + def select_tag(name, option_tags = nil, options = {}) + content_tag("select", option_tags, { "name" => name, "id" => name }.update(options)) + end + def text_field_tag(name, value = nil, options = {}) tag("input", {"type" => "text", "name" => name, "id" => name, "value" => value}.update(options)) end + def hidden_field_tag(name, value = nil, options = {}) + text_field_tag(name, value, options.update("type" => "hidden")) + end + def password_field_tag(name = "password", value = nil, options = {}) - tag("input", {"type" => "password", "name" => name, "id" => name, "value" => value}.update(options)) + text_field_tag(name, value, options.update("type" => "password")) end def text_area_tag(name, content = nil, options = {}) @@ -54,6 +62,12 @@ module ActionView tag("input", html_options) end + def radio_button_tag(name, value, checked = false, options = {}) + html_options = {"type" => "radio", "name" => name, "id" => name, "value" => value}.update(options) + html_options["checked"] = "checked" if checked + tag("input", html_options) + end + def submit_tag(value = "Save changes", options = {}) tag("input", {"type" => "submit", "name" => "submit", "value" => value}.update(options)) end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 5806c879fd..25da1937d4 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -8,9 +8,12 @@ class TagHelperTest < Test::Unit::TestCase MethodToTag = { %(text_field_tag("title", "Hello!")) => %(<input id="title" name="title" type="text" value="Hello!" />), %(text_field_tag("title", "Hello!", "class" => "admin")) => %(<input class="admin" id="title" name="title" type="text" value="Hello!" />), + %(hidden_field_tag "id", 3) => %(<input id="id" name="id" type="hidden" value="3" />), %(password_field_tag) => %(<input id="password" name="password" type="password" value="" />), %(text_area_tag("body", "hello world", :size => "20x40")) => %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>), %(check_box_tag("admin")) => %(<input id="admin" name="admin" type="checkbox" value="1" />), + %(radio_button_tag("people", "david")) => %(<input id="people" name="people" type="radio" value="david" />), + %(select_tag("people", "<option>david</option>")) => %(<select id="people" name="people"><option>david</option></select>), } def test_tags |