Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11570 from joelcogen/harmonize_text_field_and_area

text_area should handle nil value option like text_field
Conflicts:
	actionview/CHANGELOG.md
  • Loading branch information...
commit 5e0307e67e35be068730f6701f5fcc69cfe8bf40 1 parent d89b19d
@rafaelfranca rafaelfranca authored
View
14 actionpack/CHANGELOG.md
@@ -1,5 +1,19 @@
## unreleased ##
+* Fix `text_area` to behave like `text_field` when `nil` is given as
+ value.
+
+ Before:
+
+ f.text_field :field, value: nil #=> <input value="">
+ f.text_area :field, value: nil #=> <textarea>value of field</textarea>
+
+ After:
+
+ f.text_area :field, value: nil #=> <textarea></textarea>
+
+ *Joel Cogen*
+
* Fix an issue where Journey was failing to clear the named routes hash when the
routes were reloaded and since it doesn't overwrite existing routes then if a
route changed but wasn't renamed it kept the old definition. This was being
View
2  actionpack/lib/action_view/helpers/tags/text_area.rb
@@ -10,7 +10,7 @@ def render
options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
end
- content_tag("textarea", options.delete('value') || value_before_type_cast(object), options)
+ content_tag("textarea", options.delete("value") { value_before_type_cast(object) }, options)
end
end
end
View
4 actionpack/lib/action_view/helpers/tags/text_field.rb
@@ -5,8 +5,8 @@ class TextField < Base # :nodoc:
def render
options = @options.stringify_keys
options["size"] = options["maxlength"] unless options.key?("size")
- options["type"] ||= field_type
- options["value"] = options.fetch("value"){ value_before_type_cast(object) } unless field_type == "file"
+ options["type"] ||= field_type
+ options["value"] = options.fetch("value") { value_before_type_cast(object) } unless field_type == "file"
options["value"] &&= ERB::Util.html_escape(options["value"])
add_default_name_and_id(options)
tag("input", options)
View
7 actionpack/test/template/form_helper_test.rb
@@ -676,6 +676,13 @@ def test_text_area_with_alternate_value
)
end
+ def test_text_area_with_nil_alternate_value
+ assert_dom_equal(
+ %{<textarea id="post_body" name="post[body]">\n</textarea>},
+ text_area("post", "body", value: nil)
+ )
+ end
+
def test_text_area_with_html_entities
@post.body = "The HTML Entity for & is &amp;"
assert_dom_equal(
Please sign in to comment.
Something went wrong with that request. Please try again.