diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2012-02-02 03:38:13 -0800 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2012-02-02 03:38:13 -0800 |
commit | 3ccbc619e4e1614c94d19cc9d12bbe7f7826cbdf (patch) | |
tree | b165ff3ec49f2215f205bdc8abafbe3eb6d3949b | |
parent | 593fe4312fc15fba458cf14e1154eeb8a8ded37c (diff) | |
parent | 3d1095563c7d6f3e32bddbf9008607d921061e58 (diff) | |
download | rails-3ccbc619e4e1614c94d19cc9d12bbe7f7826cbdf.tar.gz rails-3ccbc619e4e1614c94d19cc9d12bbe7f7826cbdf.tar.bz2 rails-3ccbc619e4e1614c94d19cc9d12bbe7f7826cbdf.zip |
Merge pull request #4849 from carlosantoniodasilva/checkbox-hidden-form
Replicate :form html5 attribute to hidden field for check_box
-rw-r--r-- | actionpack/CHANGELOG.md | 3 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/check_box.rb | 6 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 13 |
3 files changed, 18 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 0dafef90ae..38d5f0b4e5 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,8 @@ ## Rails 4.0.0 (unreleased) ## +* check_box with `:form` html5 attribute will now replicate the `:form` + attribute to the hidden field as well. *Carlos Antonio da Silva* + * `label` form helper accepts :for => nil to not generate the attribute. *Carlos Antonio da Silva* * Add `:format` option to number_to_percentage *Rodrigo Flores* diff --git a/actionpack/lib/action_view/helpers/tags/check_box.rb b/actionpack/lib/action_view/helpers/tags/check_box.rb index 7ad5de0596..579cdb9fc9 100644 --- a/actionpack/lib/action_view/helpers/tags/check_box.rb +++ b/actionpack/lib/action_view/helpers/tags/check_box.rb @@ -25,7 +25,7 @@ module ActionView add_default_name_and_id(options) end - hidden = @unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => @unchecked_value, "disabled" => options["disabled"]) : "".html_safe + hidden = hidden_field_for_checkbox(options) checkbox = tag("input", options) hidden + checkbox end @@ -48,6 +48,10 @@ module ActionView value.to_i != 0 end end + + def hidden_field_for_checkbox(options) + @unchecked_value ? tag("input", options.slice("name", "disabled", "form").merge!("type" => "hidden", "value" => @unchecked_value)) : "".html_safe + end end end end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 4e440c6a13..9366960caa 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -421,6 +421,13 @@ class FormHelperTest < ActionView::TestCase ) end + def test_checkbox_form_html5_attribute + assert_dom_equal( + '<input form="new_form" name="post[secret]" type="hidden" value="0" /><input checked="checked" form="new_form" id="post_secret" name="post[secret]" type="checkbox" value="1" />', + check_box("post", "secret", :form => "new_form") + ) + end + def test_radio_button assert_dom_equal('<input checked="checked" id="post_title_hello_world" name="post[title]" type="radio" value="Hello World" />', radio_button("post", "title", "Hello World") @@ -2168,8 +2175,8 @@ class FormHelperTest < ActionView::TestCase end protected - def protect_against_forgery? - false - end + def protect_against_forgery? + false + end end |