Re: formulator troubles
Andy Altepeter <[email protected]> Tue, 24 May 2005 09:56:58 -0500
| Newsgroups | gmane.comp.web.zope.silva.general,gmane.comp.web.zope.formulator.devel |
|---|---|
| Message-ID | <[email protected]> |
> dutch | dutch, english | english > > the code stated above will split this into pieces where it encounters a > comma. When multiple boxes are checked this does work and everything works > well. But for some reason when someon just checked one box I get the > following output: > > d,u,t,c,h, > > I dont know whats causing this because im using the same technnique on > adding ( creating ) a new object to create the xml out of the data im > getting from the form. Also why does it insert comma's when it has to join > ? Is it a string, or is it a list? Unfortunately, strings are also lists. If the zope marshaller finds a name in REQUEST.form having multiple values, it places those values in a list. However, if there is only one value for a name, it stays as is. Once can force list conversion by adding ':list' to the input fields name. I don't know how to do this in formulator, perhaps using tales? You probably want to try the following in submit_edit: sel = requst_value if ( same_type(request_value, '') ): sel = [sel] sel is your multicheckbox list from request.form. After this code, you can assume sel is a list of strings (or whatever). same_type isn't really documented, but is available at least in python scripts, dtml, and page templates. One can probably import it into product code, but there it is just as easy to use is_instance or the like. This has been a troublesome quirk for me in the past, too ;-) > I tried to fix this by inserting a if statement that counted the elements > and if it was bigger then 1 join the element's otherwise get me the value > of the first. This didnt work, why I dont know because it just gave me a > runtime error without telling me what's wrong. Not sure what your code was, but len() will be > 1 if the object you think is a list of strings is actually just a string, so that won't really work. HTH, Andy