Re: formulator troubles

Reinout van Rees <[email protected]> Wed, 25 May 2005 08:26:00 +0200 (CEST)
Newsgroups gmane.comp.web.zope.formulator.devel
Message-ID <[email protected]>
On Tue, 24 May 2005, Somhorst JJT wrote:

> For the multicheckboxes this is something like this:
>
> editor.replace_text(node, ', '.join(request['field_'+node.nodeName]))
>
> if someone checked only 1 value in the formfield it goes wrong.. lets say i
> have the following values:
>
> 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,

In the core, the problem is that a string is more or less the same as
a list... So:

>>> ','.join('string')  # looks like ['s', 't', ...]
's,t,r,i,n,g'
>>> ','.join(['list'])  # now it's a one-item list
'list'

So you might want to test "if type(back_from_request) == type('aaa')".
But as you're probably getting stuff from an http request: there is a
way to tell the form mechanism that it's a list you're sending. In
your html form put something like <input name="yourfield:list" ....>
in your form. I couldn't find a doc for it right away. But this should
convince the request mechanism to give you a list at all times, even
for only one item.

Reinout

-- 
Reinout van Rees                  r.van.rees-1kr/[email protected]
http://vanrees.org/weblog/            http://zestsoftware.nl
"engineer: a mechanism for converting caffeine into designs"