In fact, this seems to be a bug not so much with setting default values,
but with form validation.
I am doing:
if form.process().accepted:
and somehow, in this validation process, if the string fields are ['a',
'b'] (the string 'a' filled in the first entry line, and 'b' in the second
line), then after validation, this is turned into ["['a', 'b']", "['a',
'b']"], so that each of the two fields consists now of the string "['a',
'b']". The bug seems to be in the validation. Am I doing something wrong,
or is this a web2py bug?
Luca
On Friday, September 21, 2012 3:20:28 PM UTC-7, Luca wrote:
>
> I have the following code snippet:
>
> form = SQLFORM.factory(Field('members', 'list:string',
> requires=IS_LIST_OF(IS_IN_DB(db, 'auth_user.email', '%(email)s')),
> ))
> form.vars.members = current_emails
>
> This does not work. if current_email is ['[email protected]'] for instance, then
> the field gets populated with the string '[[email protected]]' (including the
> square brackets!).
> I tried also:
>
> form = SQLFORM.factory(Field('members', 'list:string',
> requires=IS_LIST_OF(IS_IN_DB(db, 'auth_user.email', '%(email)s')),
> default=current_emails
> ))
>
> but this causes an even weirder problem. If the user enters [email protected], and
> [email protected] as the two emails, assuming they do not belong to any user, then
> the form is redisplayed with a notice that there were errors, but on EACH
> of the two entries of the form, the single email addresses are BOTH
> replaced with the string "['[email protected]', '[email protected]']" .
>
> I guess this is a bug?
> How can I specify the initial value for a list:string field in a
> SQLFORM.factory form?
> Many thanks!
>
> Luca
>
--