summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--lib/cgi/html.rb16
-rwxr-xr-xtest/cgi/test_cgi_tag_helper.rb11
3 files changed, 27 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 674caee0a78..00c5c357636 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Mon Sep 29 00:30:20 2008 Takeyuki Fujioka <xibbar@ruby-lang.org>
+
+ * lib/cgi/html.rb (CGI::HtmlExtension::{radio_group, checkbox_group}):
+ can specify the false as checked or selected value.
+ [ruby-core:18306], [ruby-core:18307]
+
+ * test/cgi/test_cgi_tag_helper.rb: add a test.
+
Sun Sep 28 23:08:38 2008 Takeyuki Fujioka <xibbar@ruby-lang.org>
* lib/cgi/html.rb (CGI::HtmlExtension::popup_menu):
diff --git a/lib/cgi/html.rb b/lib/cgi/html.rb
index aac53f92563..74aa730be71 100644
--- a/lib/cgi/html.rb
+++ b/lib/cgi/html.rb
@@ -248,12 +248,12 @@ class CGI
if value.kind_of?(String)
checkbox(name, value) + value
else
- if value[value.size - 1] == true
- checkbox(name, value[0], true) +
- value[value.size - 2]
+ if value[-1] == true || value[-1] == false
+ checkbox(name, value[0], value[-1]) +
+ value[-2]
else
checkbox(name, value[0]) +
- value[value.size - 1]
+ value[-1]
end
end
}.join
@@ -703,12 +703,12 @@ class CGI
if value.kind_of?(String)
radio_button(name, value) + value
else
- if value[value.size - 1] == true
- radio_button(name, value[0], true) +
- value[value.size - 2]
+ if value[-1] == true || value[-1] == false
+ radio_button(name, value[0], value[-1]) +
+ value[-2]
else
radio_button(name, value[0]) +
- value[value.size - 1]
+ value[-1]
end
end
}.join
diff --git a/test/cgi/test_cgi_tag_helper.rb b/test/cgi/test_cgi_tag_helper.rb
index 38533a11e80..618130b8223 100755
--- a/test/cgi/test_cgi_tag_helper.rb
+++ b/test/cgi/test_cgi_tag_helper.rb
@@ -313,6 +313,17 @@ class CGITagHelperTest < Test::Unit::TestCase
assert_match(/^<INPUT .*VALUE="aa".*>bb<INPUT .*VALUE="cc".*>dd$/,str)
assert_match(/^<INPUT .*TYPE="radio".*>bb<INPUT .*TYPE="radio".*>dd$/,str)
assert_match(/^<INPUT .*NAME="foo".*>bb<INPUT .*NAME="foo".*>dd$/,str)
+ str=cgi.checkbox_group("foo",["aa","bb"],["cc","dd",true])
+ assert_match(/^<INPUT .*VALUE="aa".*>bb<INPUT .*VALUE="cc".*>dd$/,str)
+ assert_match(/^<INPUT .*TYPE="checkbox".*>bb<INPUT .*TYPE="checkbox".*>dd$/,str)
+ assert_match(/^<INPUT .*NAME="foo".*>bb<INPUT .*NAME="foo".*>dd$/,str)
+ assert_match(/^<INPUT .*>bb<INPUT .*CHECKED.*>dd$/,str)
+ if RUBY_VERSION>="1.9"
+ str=cgi.radio_group("foo",["aa","bb"],["cc","dd",false])
+ assert_match(/^<INPUT .*VALUE="aa".*>bb<INPUT .*VALUE="cc".*>dd$/,str)
+ assert_match(/^<INPUT .*TYPE="radio".*>bb<INPUT .*TYPE="radio".*>dd$/,str)
+ assert_match(/^<INPUT .*NAME="foo".*>bb<INPUT .*NAME="foo".*>dd$/,str)
+ end
end
=begin