Skip to content
Browse files

Fixed FormTagHelper#check_box to respect checked #1049 [DelynnB]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1183 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent e5b3d08 commit ba96827b3d05396b11491e36590c52a407ddb8a2 @dhh dhh committed Apr 17, 2005
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed FormTagHelper#check_box to respect checked #1049 [DelynnB]
+
* Added that render_partial called from a controller will use the action name as default #828 [Dan Peterson]
* Added Element.toggle, Element.show, and Element.hide to the prototype javascript library. Toggle.display has been deprecated, but will still work #992 [Lucas Carlson]
View
2 actionpack/lib/action_view/helpers/form_helper.rb
@@ -199,7 +199,7 @@ def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
else
value.to_i != 0
end
- if checked
+ if checked || options["checked"] == "checked"
options["checked"] = "checked"
else
options.delete("checked")
View
7 actionpack/test/template/form_helper_test.rb
@@ -1,6 +1,7 @@
require 'test/unit'
require 'erb'
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
+require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/hash' #for stringify keys
class FormHelperTest < Test::Unit::TestCase
include ActionView::Helpers::FormHelper
@@ -64,13 +65,15 @@ def test_check_box
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret")
)
-
@post.secret = 0
assert_equal(
'<input id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret")
)
-
+ assert_equal(
+ '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
+ check_box("post", "secret" ,{"checked"=>"checked"})
+ )
@post.secret = true
assert_equal(
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',

0 comments on commit ba96827

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