On Saturday, November 18, 2017 at 6:57:54 PM UTC-5, Donald McClymont wrote: > > Issue may be with SQLFORM rather than Pydal - if I have a list string > field in my case its called answers and put it in a SQLFORM then in > form.validate if you do > > print type(form.vars.answers) > > I get str when there is 1 item in my list and list when multiple answers and > so my validation includes a line like this: > > > if isinstance(form.vars.answers, list) and len(form.vars.answers) > 1 and > len(form.vars.answers[1]) > 0: > > > I just thought I'd mention it as something to be aware of if you start using > length with list string fields as I always expected it to be a list. > > > This is still the case with 2.16.1 > > Got it. That has to do with the widget used to represent list:string fields in forms. It simply creates one or more inputs with the same name. When there is only one item, the value in request.vars and therefore form.vars is just a string, but when there are multiple form elements with the same name, request.vars and form.vars ends up as a list. SQLFORM.accepts does ultimately convert a single string in form.vars to a single element list, but not until after the onvalidation function has been run. Feel free to submit a Github issue about this (in the web2py repo, as it is related to SQLFORM, not PyDAL).
Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.