aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-01-27 13:14:37 +0100
committerJosé Valim <jose.valim@gmail.com>2012-01-27 13:15:52 +0100
commit2e5ec3b3996231c3b770844608fb7b41c0d891e6 (patch)
tree4992ab1552dd859ca55cec495a7fc465f52bb133 /actionpack
parent1c5bd8a33dd7002c8664e587f968830c1bce3ff8 (diff)
parentdefb751681640e11f2187439acdaaa12ca9b805f (diff)
downloadrails-2e5ec3b3996231c3b770844608fb7b41c0d891e6.tar.gz
rails-2e5ec3b3996231c3b770844608fb7b41c0d891e6.tar.bz2
rails-2e5ec3b3996231c3b770844608fb7b41c0d891e6.zip
Merge check box fixes from remote-tracking branch 'cantonio/checkbox-hidden-backport' into 3-2-stable
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md6
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb2
-rw-r--r--actionpack/test/template/form_helper_test.rb15
3 files changed, 18 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index f40b7a2449..1e446ad0be 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,9 @@
+## Rails 3.2.2 (unreleased) ##
+
+* check_box helper with :disabled => true will generate a disabled hidden field to conform with the HTML convention where disabled fields are not submitted with the form.
+ This is a behavior change, previously the hidden tag had a value of the disabled checkbox.
+ *Tadas Tamosauskas*
+
## Rails 3.2.1 (January 26, 2012) ##
* Documentation improvements.
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index ffb5a729ed..294dee8e2a 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -1092,7 +1092,7 @@ module ActionView
else
add_default_name_and_id(options)
end
- hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => options['disabled'] && checked ? checked_value : unchecked_value)
+ hidden = unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"]) : ""
checkbox = tag("input", options)
(hidden + checkbox).html_safe
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 73b936b16e..6e26fe752e 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -373,6 +373,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(
@@ -385,11 +393,10 @@ class FormHelperTest < ActionView::TestCase
)
end
-
- def test_checkbox_disabled_still_submits_checked_value
+ def test_checkbox_disabled_disables_hidden_field
assert_dom_equal(
- '<input name="post[secret]" type="hidden" value="1" /><input checked="checked" disabled="disabled" id="post_secret" name="post[secret]" type="checkbox" value="1" />',
- check_box("post", "secret", { :disabled => :true })
+ '<input name="post[secret]" type="hidden" value="0" disabled="disabled"/><input checked="checked" disabled="disabled" id="post_secret" name="post[secret]" type="checkbox" value="1" />',
+ check_box("post", "secret", { :disabled => true })
)
end