On Apr 18, 5:30 pm, Ian Bicking <[EMAIL PROTECTED]> wrote:
> Graham Stratton wrote:
> > I've got a really frustrating problem which I'm hoping someone
> > familiar with FormEncode in Pylons can shed some light on.
>
> > A few weeks ago I added a form to my project which includes multiple
> > selects.   The form data is validated by a validate decorator using a
> > FormEncode schema with ForEach validators for the multiple fields.
> > This all worked fine, and when there were errors the multiple values
> > were correctly selected on error page.
>
> > At some point something changed, and I started only ever getting a
> > single value for the multiple fields.  I still can't work out what
> > changed.  I managed to get multiple values working again by setting
> > variable_decode=True in the decorator, but but if an error occurs only
> > one item from each multiple item is selected in the redrawn form.
>
> > Reading the source and using the debugger, it appears that:
>
> > paste.request.parse_formvars writes a MultiDict with repeating keys to
> > environ['paste.parsed_formvars']
> > The validate decorator just passes on the request vars unless
> > variable_decode is set
> > Schema._to_python iterates over each item in the dict
> > The ForEach validator expects a list for each value
>
> > It seems that at some point getall() needs to be called on the
> > MultiDict, but I can't see where.  Any ideas what I am (now!) doing
> > wrong?
>
> Huh... it looks like variable_decode should work to me.  variable_decode
> uses vars.items(); for MultiDict that produces all the tuples, including
> duplicates.  Though maybe that function is written with the expectation
> that a key won't show up twice -- which is exactly what MultiDict
> produces.  vars.mixed() will return a more typical dictionary, where
> multiple values turn into a list in the value.
>
> Looking at the code briefly, it seems like it should work anyway; for
> each key it checks if they key already exists in the nested dictionary
> being created, and adds the value in if that's the case.  A repeatable
> example of a failure would help most; MultiDict's repr is good, so maybe
> even an example of a multidict which doesn't work the way you think it
> should when it goes through variable_decode.

Hi Ian, thanks for your response.

I'm afraid I'm not quite getting this. Do I always need to set
variable_decode=True in order to use validate multiple form inputs?
This isn't clear anywhere.  If so, why isn't it the default?

Setting variable_decode does make the form return multiple values, but
htmlfill still fails because in Pylons 0.9.5 htmlfill is passed the
params dictionary which has not been passed to variabledecode.

Ticket 209 seems to be the same issue; indeed, I had independently
implemented the first patch.  http://pylonshq.com/project/pylonshq/ticket/209

Thanks,

Graham


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to