Possible bug in CGI::HtmlExtension::popup_menu?

M

Mallory Cloutier

Hi all,
I'm trying to use popup_menu to generate a select box that remembers
what option it had selected when the page was generated. The relevant
lines of code are

dura_list = cgi.popup_menu("dura",
["300", "Five minutes", (timespan == 300)],
["600", "Ten minutes", (timespan == 600)],
["900", "Fifteen minutes", (timespan == 900)])

where timespan has already been set to either the integer value of the
parameter "dura" or to a default value of 300.

According to the documentation as I understand it, this should generate

<SELECT NAME="dura"><OPTION SELECTED VALUE="300">Five
minutes</OPTION><OPTION VALUE="600">Ten minutes</OPTION><OPTION
VALUE="900">Fifteen minutes</OPTION></SELECT> <br>

but instead it generates

<SELECT NAME="dura"><OPTION SELECTED VALUE="300">Five
minutes</OPTION><OPTION VALUE="600">false</OPTION><OPTION
VALUE="900">false</OPTION></SELECT> <br>

Looking through the source for popup_menu on
http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html, I found

if value.kind_of?(String)
option({ "VALUE" => value }){ value }
else
if value[value.size - 1] == true
option({ "VALUE" => value[0], "SELECTED" => true }){
value[value.size - 2]
}
else
option({ "VALUE" => value[0] }){
value[value.size - 1]
}
end
end

which I think is causing this. Since value[value.size - 1] is false,
the last else clause is getting triggered and using that as the option
text. I wasn't able to find any other reports of this to see if there's
a workaround or fix yet.
 
M

Mallory Cloutier

Just as a note, there seems to be a similar issue with explicit "false"
in checkbox_group. Are these really bugs, or am I just misunderstanding
how these methods are meant to be used, or what?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top