Skip to content

Commit

Permalink
Allow radio buttons to work with booleans.
Browse files Browse the repository at this point in the history
[#2937 state:committed]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
josevalim authored and jeremy committed Aug 10, 2009
1 parent d0bdff0 commit e972acc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -861,8 +861,8 @@ def radio_button_checked?(value, checked_value)

private
def add_default_name_and_id_for_value(tag_value, options)
if tag_value
pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
unless tag_value.nil?
pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
specified_id = options["id"]
add_default_name_and_id(options)
options["id"] += "_#{pretty_tag_value}" unless specified_id
Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -311,6 +311,16 @@ def test_radio_button_respects_passed_in_id
)
end

def test_radio_button_with_booleans
assert_dom_equal('<input id="post_secret_true" name="post[secret]" type="radio" value="true" />',
radio_button("post", "secret", true)
)

assert_dom_equal('<input id="post_secret_false" name="post[secret]" type="radio" value="false" />',
radio_button("post", "secret", false)
)
end

def test_text_area
assert_dom_equal(
'<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
Expand Down

0 comments on commit e972acc

Please sign in to comment.