From f400209084fabb00e18c3325e1933f4543fce94c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 10 Feb 2009 13:10:46 -0600 Subject: [PATCH] Move checkbox hidden field before the actual checkbox so the actual value doesn't get clobbered [#1863 state:resolved] --- .../lib/action_view/helpers/form_helper.rb | 4 +- actionpack/test/template/form_helper_test.rb | 72 +++++++++---------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 0651f75cfb8f7..3925978217d9f 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -753,7 +753,9 @@ def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0") end options["checked"] = "checked" if checked add_default_name_and_id(options) - tag("input", options) << tag("input", "name" => options["name"], "type" => "hidden", "value" => options['disabled'] && checked ? checked_value : unchecked_value) + hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => options['disabled'] && checked ? checked_value : unchecked_value) + checkbox = tag("input", options) + hidden + checkbox end def to_boolean_select_tag(options = {}) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index b7ea2c0176329..b7e4a933e172b 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -170,36 +170,36 @@ def test_text_field_with_options def test_check_box assert_dom_equal( - '', + '', check_box("post", "secret") ) @post.secret = 0 assert_dom_equal( - '', + '', check_box("post", "secret") ) assert_dom_equal( - '', + '', check_box("post", "secret" ,{"checked"=>"checked"}) ) @post.secret = true assert_dom_equal( - '', + '', check_box("post", "secret") ) assert_dom_equal( - '', + '', check_box("post", "secret?") ) @post.secret = ['0'] assert_dom_equal( - '', + '', check_box("post", "secret") ) @post.secret = ['1'] assert_dom_equal( - '', + '', check_box("post", "secret") ) end @@ -207,14 +207,14 @@ def test_check_box def test_check_box_with_explicit_checked_and_unchecked_values @post.secret = "on" assert_dom_equal( - '', + '', check_box("post", "secret", {}, "on", "off") ) end def test_checkbox_disabled_still_submits_checked_value assert_dom_equal( - '', + '', check_box("post", "secret", { :disabled => :true }) ) end @@ -289,7 +289,7 @@ def test_explicit_name text_area("post", "body", "name" => "really!") ) assert_dom_equal( - '', + '', check_box("post", "secret", "name" => "i mean it") ) assert_dom_equal text_field("post", "title", "name" => "dont guess"), @@ -309,7 +309,7 @@ def test_explicit_id text_area("post", "body", "id" => "really!") ) assert_dom_equal( - '', + '', check_box("post", "secret", "id" => "i mean it") ) assert_dom_equal text_field("post", "title", "id" => "dont guess"), @@ -334,7 +334,7 @@ def test_auto_index text_area("post[]", "body") ) assert_dom_equal( - "", + "", check_box("post[]", "secret") ) assert_dom_equal( @@ -360,8 +360,8 @@ def test_form_for "" + "" + "" + - "" + "" + + "" + "" + "" @@ -380,8 +380,8 @@ def test_form_for_with_method "
" + "" + "" + - "" + "" + + "" + "" assert_dom_equal expected, output_buffer @@ -398,8 +398,8 @@ def test_form_for_without_object "
" + "" + "" + - "" + "" + + "" + "
" assert_dom_equal expected, output_buffer @@ -418,8 +418,8 @@ def test_form_for_with_index "" + "" + "" + - "" + "" + + "" + "" assert_dom_equal expected, output_buffer @@ -436,8 +436,8 @@ def test_form_for_with_nil_index_option_override "
" + "" + "" + - "" + "" + + "" + "
" assert_dom_equal expected, output_buffer @@ -708,8 +708,8 @@ def test_fields_for expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -724,8 +724,8 @@ def test_fields_for_with_index expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -740,8 +740,8 @@ def test_fields_for_with_nil_index_option_override expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -756,8 +756,8 @@ def test_fields_for_with_index_option_override expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -772,8 +772,8 @@ def test_fields_for_without_object expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -788,8 +788,8 @@ def test_fields_for_with_only_object expected = "" + "" + - "" + - "" + "" + + "" assert_dom_equal expected, output_buffer end @@ -834,8 +834,8 @@ def test_form_for_and_fields_for "
" + "" + "" + - "" + "" + + "" + "
" assert_dom_equal expected, output_buffer @@ -883,8 +883,7 @@ def test_form_for_with_labelled_builder "
" + "
" + "
" + - " " + - "
" + + "
" + "
" assert_dom_equal expected, output_buffer @@ -904,8 +903,7 @@ def test_default_form_builder "
" + "
" + "
" + - " " + - "
" + + "
" + "
" assert_dom_equal expected, output_buffer @@ -960,8 +958,7 @@ def test_remote_form_for_with_labelled_builder %(
) + "
" + "
" + - " " + - "
" + + "
" + "
" assert_dom_equal expected, output_buffer @@ -977,8 +974,7 @@ def test_fields_for_with_labelled_builder expected = "
" + "
" + - " " + - "
" + "
" assert_dom_equal expected, output_buffer end