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

Completed FormTagHelper by adding radio_button_tag and select_tag

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@688 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-02-19 13:09:09 +00:00
parent 967339e4d3
commit ad1fe7dd27
2 changed files with 18 additions and 1 deletions

View file

@ -31,12 +31,20 @@ module ActionView
"</form>" "</form>"
end 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 = {}) def text_field_tag(name, value = nil, options = {})
tag("input", {"type" => "text", "name" => name, "id" => name, "value" => value}.update(options)) tag("input", {"type" => "text", "name" => name, "id" => name, "value" => value}.update(options))
end 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 = {}) 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 end
def text_area_tag(name, content = nil, options = {}) def text_area_tag(name, content = nil, options = {})
@ -54,6 +62,12 @@ module ActionView
tag("input", html_options) tag("input", html_options)
end 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 = {}) def submit_tag(value = "Save changes", options = {})
tag("input", {"type" => "submit", "name" => "submit", "value" => value}.update(options)) tag("input", {"type" => "submit", "name" => "submit", "value" => value}.update(options))
end end

View file

@ -8,9 +8,12 @@ class TagHelperTest < Test::Unit::TestCase
MethodToTag = { MethodToTag = {
%(text_field_tag("title", "Hello!")) => %(<input id="title" name="title" type="text" value="Hello!" />), %(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!" />), %(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="" />), %(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>), %(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" />), %(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 def test_tags