Skip to content

Commit

Permalink
Fixed FormTagHelper#check_box to respect checked #1049 [DelynnB]
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1183 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Apr 17, 2005
1 parent e5b3d08 commit ba96827
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions 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]
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -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")
Expand Down
7 changes: 5 additions & 2 deletions 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
Expand Down Expand Up @@ -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" />',
Expand Down

0 comments on commit ba96827

Please sign in to comment.