Consider a form: <form action="Post"> <select name="Values" multiple> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select> ... I have the request handling stuff working 100%, except for the case when the user selects only a single value. This seems to be because Zope converts result values to a list. So, if the user selects multiple values, form.Values becomes a list, like: ['A', 'B', 'C'] But if the user selects a single value, form.Values becomes a single value, like 'A' How do I effectively and foolproofly handle this sort of case? Although the solution ought to be indepedent of my specific code, I ought to explain a bit. Basically, my code aims to join two lists: one gotten from a <select>, the other from a simple <input>. It looks like this: <!-- first, convert from a list into a simple string, delimited with "," --> <!--#call "REQUEST.set('select', _.string.join(select, ','))"--> <!-- then join the two strings into a list based on the assumed delimiter --> <!--#call "REQUEST.set('values, _.string.join(_.string.split(select + input, ','), ','))"--> Yeah, not very pretty. Anyway, if select is ['A', 'B'] and input is 'C, D', the resulting string should because 'A', 'B', 'C', 'D'. Easy as pie, and it works fine, except if select isn't a list. In Python, you can simply check the type of variable: if type(select) == type([]): ... But this won't work in Zope. Any suggestions? Alexander Staubo http://www.mop.no/~alex/ mailto:redhand@mop.no
Hi - On Thu, 6 May 1999, Alexander Staubo wrote:
Consider a form:
<form action="Post"> <select name="Values" multiple> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select> ...
Try: <select name="Values:list" multiple> this will ensure that Value is a list whatever the selection Pavlos
Hi -
On Thu, 6 May 1999, Alexander Staubo wrote:
Consider a form:
<form action="Post"> <select name="Values" multiple> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select> ...
Try:
<select name="Values:list" multiple> this will ensure that Value is a list whatever the selection
In my case, I am using a tclet (the tclet supports POST) to do the equivalent of a form (the big advantage is that I can have tk widgets like slides and spinners in the tclet for inputting values. Is there a way of doing this declaration of form variable w/o having the explicit form in the document? Regards, Albert Boulanger aboulanger@ldeo.columbia.edu
participants (3)
-
aboulanger@ldeo.columbia.edu -
Alexander Staubo -
Pavlos Christoforou