Multi-option checkboxes. Suggestion?

2 views
Skip to first unread message

James Masters

unread,
May 12, 2008, 8:47:42 AM5/12/08
to Rose::HTML::Objects
Is is sometimes desireable to use checkboxes differently to radio
buttons (which can only have one value) so that more than one checkbox
in a list can be selected. e.g. a user might check 3 checkboxes:
apples, oranges & pears out of a list of 10 fruit.

HTML deals with this badly because the only way to do this (AFAIK) is
to create a differently name checkbox for each option and then a
script is forced to assess the name of the form field in order to work
out which of the options are checked.

I may be wrong here but I think that checkboxes are dealt with by
RHTMLO in exactly the same way as radio buttons. I've setting up a
form with checkbox that will allow multiple values to be selected and
am therefore having to create individual checkbox fields rather than
use a checkboxgroup because a single name won't do.

However, it occurred to me that Rose could probably hide the
cumbersome HTML behaviour and have a type CheckboxMultigroup or
something that would create differently name checkboxes and then upon
receipt agglomerate them back into a single field that could be
interrogated in a slightly different way to a radiobutton/
checkboxgroup to allow for multiple values.

This is just a suggestion because it would be a convenient thing. But
if this can be done somehow already, then it's not a suggestion, it's
a question....

thanks,

James.

John Siracusa

unread,
May 12, 2008, 10:11:03 AM5/12/08
to rose-htm...@googlegroups.com
On Mon, May 12, 2008 at 8:47 AM, James Masters <ja...@mastersgames.com> wrote:
> Is is sometimes desireable to use checkboxes differently to radio
> buttons (which can only have one value) so that more than one checkbox
> in a list can be selected. e.g. a user might check 3 checkboxes:
> apples, oranges & pears out of a list of 10 fruit.
>
> HTML deals with this badly because the only way to do this (AFAIK) is
> to create a differently name checkbox for each option

This is not the case. What RHTMLO does (and what the HTML standards
explicitly support) is use the same name="..." but a different
value="..." for each checkbox HTML element. Submitting such a form
results in a query that contains the same query param with multiple
values. For example:

size=123&lang=en&lang=fr&lang=de

Your web framework or CGI engine or other such code should convert
such a submission into a hash suitable for passing to RHTMLO's
params() method:

{
size => 123,
lang => [ 'en', 'fr', 'de' ],
}

From the HTMLO 4.01 spec (merely the first place I looked to grab a quote):

"Several checkboxes in a form may share the same control name. Thus,
for example, checkboxes allow users to select several values for the
same property."

That's what a CheckBoxGroup is modeling: a single property with multiple values.

-John

James Masters

unread,
May 13, 2008, 4:17:37 AM5/13/08
to Rose::HTML::Objects
Aha, thanks. I can't believe I have been labouring under this
misunderstanding for so long. When I did it like this, my debugging
routine that list cgi params passed only showed one value so I had
assumed any other selected values were lost. I've fixed my debugging
routine and all is clear. Thanks.
Reply all
Reply to author
Forward
0 new messages