Skip to content
Browse files

Merge pull request #4353 from dmathieu/hide_nil_unchecked_checkbox

don't set the hidden checkbox value if it's nil
  • Loading branch information...
2 parents aec8172 + 69a6381 commit 365a34c92f7fa95605bc34ea2d5ac70da5790e9d @josevalim josevalim committed Jan 6, 2012
View
2 actionpack/lib/action_view/helpers/form_helper.rb
@@ -1091,7 +1091,7 @@ def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
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
View
8 actionpack/test/template/form_helper_test.rb
@@ -374,6 +374,14 @@ def test_check_box_with_explicit_checked_and_unchecked_values
)
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(

0 comments on commit 365a34c

Please sign in to comment.
Something went wrong with that request. Please try again.