The "selected" attribute is set if the option value is equal to the
input value, or is in the input value is that is a list (if you have a
number of form params with the same name, cherrypy will convert these
values to a list). Therefore you can handle both multiple and single
select values. To preselect these values, of course, just use the
"default" in the constructor.

s = SelectField("categoryID", options=[("XML", "XML Document", {}),
("HTML", "HTML Document", {})], attrs=dict(multiple="multiple"),
default=["HTML", "XML"])

Both "XML" and "HTML" are now selected. If the form input is "HTML"
then only "HTML" will be selected.

In XHTML, of course, the key/value pair is selected="selected". This is
output as 'selected' in HTML 4.0.

Reply via email to