On Mar 3, 2010, at 11:29 AM, [email protected] wrote:
>
> Thanks for all the help again. It should have been obvious to me
> before but I am sure the problem is that values coming back from
> get_last_names() are different when the form is generated compared to
> when it is validated. So I really need to just get the list of last
> names once and it use it both times.
>
> The question is how to do that. Does this look like a good approach? I
> tried it and it seems to work.
>
> if request.vars:
> db.reg_test.last_name.requires = IS_IN_SET( session.last_names,
> zero = "Select a Last Name" )
> else:
> session.last_names = get_last_names()
> db.reg_test.last_name.requires = IS_IN_SET( session.last_names,
> zero = "Select a Last Name" )
That looks plausible. You could also use the test:
if session.last_names is None:
...
Notice, though, that if that fixes the validation, you've still got the problem
that the user has selected a last name that's no longer in the database. If you
can confirm that this is indeed the bug, you might want to leave the code
as-is, since the validation failure is correct (in the sense that the selected
item is not in the database).
(And you can still have duplicate last names, which is another matter
altogether.)
--
You received this message because you are subscribed to the Google Groups
"web2py-users" 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/web2py?hl=en.