diff options
author | Tadas Tamošauskas <tadastoo@yahoo.com> | 2012-01-05 22:35:10 +0000 |
---|---|---|
committer | Tadas Tamošauskas <tadastoo@yahoo.com> | 2012-01-05 22:52:13 +0000 |
commit | 9bd38f31be61af6b3b97613100d7b89e653f73a2 (patch) | |
tree | ef9dd14096eeac8d0fc4aab2395e062d3600298d | |
parent | be52f1bf2a5e250f0e2182f2b756ac68c81718f3 (diff) | |
download | rails-9bd38f31be61af6b3b97613100d7b89e653f73a2.tar.gz rails-9bd38f31be61af6b3b97613100d7b89e653f73a2.tar.bz2 rails-9bd38f31be61af6b3b97613100d7b89e653f73a2.zip |
check_box helper with :disabled => true generates disabled hidden field. fixes #1953
-rw-r--r-- | actionpack/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 7 |
3 files changed, 8 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index f408c50390..a5370afcf1 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 3.2.0 (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* + * Add font_path helper method *Santiago Pastorino* * Depends on rack ~> 1.4.0 *Santiago Pastorino* diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 1e4bebeee7..08c7fbc281 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" => options['disabled'] && checked ? checked_value : unchecked_value) + hidden = 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 6fe4ce65cf..9a13d4e399 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -386,11 +386,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 |