Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make text_field and hidden_field omit the value attribute if the deve…

…loper explicitly passes in :value => nil [#4839 state:resolved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>

Conflicts:

	actionpack/lib/action_view/helpers/form_helper.rb
  • Loading branch information...
commit 52c922fad1e7260a4af87409d04055af85df25f8 1 parent da93d69
@NZKoz NZKoz authored
View
10 actionpack/lib/action_view/helpers/form_helper.rb
@@ -787,8 +787,8 @@ def to_input_field_tag(field_type, options = {})
if field_type == "hidden"
options.delete("size")
end
- options["type"] = field_type
- options["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"] &&= html_escape(options["value"])
add_default_name_and_id(options)
tag("input", options)
@@ -920,14 +920,14 @@ def add_default_name_and_id_for_value(tag_value, options)
def add_default_name_and_id(options)
if options.has_key?("index")
options["name"] ||= tag_name_with_index(options["index"])
- options["id"] ||= tag_id_with_index(options["index"])
+ options["id"] = options.fetch("id"){ tag_id_with_index(options["index"]) }
options.delete("index")
elsif defined?(@auto_index)
options["name"] ||= tag_name_with_index(@auto_index)
- options["id"] ||= tag_id_with_index(@auto_index)
+ options["id"] = options.fetch("id"){ tag_id_with_index(@auto_index) }
else
options["name"] ||= tag_name + (options.has_key?('multiple') ? '[]' : '')
- options["id"] ||= tag_id
+ options["id"] = options.fetch("id"){ tag_id }
end
end
View
10 actionpack/test/template/form_helper_test.rb
@@ -249,6 +249,11 @@ def test_text_field_removing_size
assert_dom_equal expected, text_field("post", "title", :maxlength => 35, :size => nil)
end
+ def test_text_field_with_nil_value
+ expected = '<input id="post_title" name="post[title]" size="30" type="text" />'
+ assert_dom_equal expected, text_field("post", "title", :value => nil)
+ end
+
def test_text_field_doesnt_change_param_values
object_name = 'post[]'
expected = '<input id="post_123_title" name="post[123][title]" size="30" type="text" value="Hello World" />'
@@ -269,6 +274,11 @@ def test_hidden_field_with_escapes
hidden_field("post", "title")
end
+ def test_hidden_field_with_nil_value
+ expected = '<input id="post_title" name="post[title]" type="hidden" />'
+ assert_dom_equal expected, hidden_field("post", "title", :value => nil)
+ end
+
def test_text_field_with_options
assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Something Else" />',
hidden_field("post", "title", :value => "Something Else")
Please sign in to comment.
Something went wrong with that request. Please try again.