aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-01-06 09:12:11 -0800
committerJosé Valim <jose.valim@gmail.com>2012-01-06 09:12:11 -0800
commit365a34c92f7fa95605bc34ea2d5ac70da5790e9d (patch)
tree92962d0f8943602277d8e1f5d3aadfba337737d4
parentaec817269f7df9641753c631d104d8b1dbdc610c (diff)
parent69a6381048b2bbf97ee651afebf43d9095ec9075 (diff)
downloadrails-365a34c92f7fa95605bc34ea2d5ac70da5790e9d.tar.gz
rails-365a34c92f7fa95605bc34ea2d5ac70da5790e9d.tar.bz2
rails-365a34c92f7fa95605bc34ea2d5ac70da5790e9d.zip
Merge pull request #4353 from dmathieu/hide_nil_unchecked_checkbox
don't set the hidden checkbox value if it's nil
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb2
-rw-r--r--actionpack/test/template/form_helper_test.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 08c7fbc281..fdddb33c31 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -1091,7 +1091,7 @@ module ActionView
else
add_default_name_and_id(options)
end
- hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"])
+ hidden = unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"]) : ""
checkbox = tag("input", options)
hidden + checkbox
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 942be67d02..ad0cc41d69 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -374,6 +374,14 @@ class FormHelperTest < ActionView::TestCase
)
end
+ def test_check_box_with_nil_unchecked_value
+ @post.secret = "on"
+ assert_dom_equal(
+ '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="on" />',
+ check_box("post", "secret", {}, "on", nil)
+ )
+ end
+
def test_check_box_with_multiple_behavior
@post.comment_ids = [2,3]
assert_dom_equal(