At 12:22 PM 11/30/01 -0500, Hsueh-ching Yen wrote:
>Hi, all
>
>I just started using webware, and have a question on HTML form submission.
>I have a
><SELECT MULTIPLE name= myselect >
><option>AAA</option>
><option>BBB</option>
><option>CCC</option>
><option>DDD</option>
></SELECT>
>If user selects one item, AAA, then submit, in HTTPRequest object
>req.fields()["myselect"] is AAA (a string).
>If user selects two item, AAA and BBB, then submit, in HTTPRequest object
>req.fields()["myselect"] is ['AAA', 'BBB'] (a list).
>
>Isn t easier if it is always in a list? Then we don t need to test the
>type of the objects?
I think it's impossible to tell the difference. The way form fields are
encoded, a single item selected in a multiple select list is the same as an
item selected in a single select list.
What I did is to write a method in my SitePage.py:
def listField(self, name):
values = self.request().field(name, [])
if not isinstance(values, types.ListType):
values = [values]
return values
Then instead of using reg.fields()["myselect"], I use
self.listField("myselect"). It'll always come back as a list.
--
- Geoff Talvola
[EMAIL PROTECTED]
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss