Permalink
Browse files

Sanitized the id generated by text_area_tag helper method. text_area_…

…tag('item[description]') should return: <textarea id="item_description" name="item[description]"></textarea> instead of: <textarea id="item[description]" name="item[description]"></textarea> The old id was causing HTML validation failures.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent 898a880 commit cd14a4a00e1005c4adcf36d2f171fb52a3c08f4f Stephen Anderson committed with NZKoz Jan 6, 2009
View
2 actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -257,7 +257,7 @@ def text_area_tag(name, content = nil, options = {})
options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
end
- content_tag :textarea, content, { "name" => name, "id" => name }.update(options.stringify_keys)
+ content_tag :textarea, content, { "name" => name, "id" => sanitize_to_id(name) }.update(options.stringify_keys)
end
# Creates a check box form input tag.
View
5 actionpack/test/template/form_tag_helper_test.rb
@@ -153,6 +153,11 @@ def test_text_area_tag_should_disregard_size_if_its_given_as_an_integer
assert_dom_equal expected, actual
end
+ def test_text_area_tag_id_sanitized
+ input_elem = root_elem(text_area_tag("item[][description]"))
+ assert_match VALID_HTML_ID, input_elem['id']
+ end
+
def test_text_field_tag
actual = text_field_tag "title", "Hello!"
expected = %(<input id="title" name="title" type="text" value="Hello!" />)

0 comments on commit cd14a4a

Please sign in to comment.