On Monday 24 November 2008 12:58:31 Eloi [entfe001] wrote:
> Another TG newbie.
>
> I have a problem with a SingleSelectField. I have a first form where
> the user selects from a SingleSelectField called Familia and then a
> second form exposes the user another SSF, called Cicle, with all the
> options related to the option selected on the first form. The second
> form constructs the SSF querying a database and filtering by the
> option on the first form.
>
> The problem comes when, on the second form, a validation error raises.
> That second form reappears displaying the errors as usual and
> refilling the form as sent but the SSF which resets to the "Pick one"
> option.
>
> I've checked that the value is passed correctly to the form, but it is
> lost when the form is displayed again.
>
> Here is the code involved:
>
>     @expose(template="solconvenis.templates.solicitud")
>     @error_handler(index)
>     @validate(form=formFamilia)
>     def solicitud(self, tg_errors=None, familia=None, cicle=None):
>         if familia == None:
>             raise redirect("/")
>         if (tg_errors):
>             flash(u"Si us plau, completeu correctament el formulari")
>         # Construcció dinàmica dels desplegables de família i cicles
>         cicles = getCiclesByFamilia(familia)
>         opcions = dict(cicle=cicles)
>         valors = dict(familia=familia,cicle=cicle)
>         return dict(form=formEmpresa,opcions=opcions,valors=valors)
>
> [...]
>
> def getCiclesByFamilia(familia):
>     """Opcions del desplegable de cicles filtrats per família
> professional."""
>     cicles = Cicle.selectBy(familia=familia)
>     opcions = [("", u"Tria un cicle")]
>     for cicle in cicles:
>         if cicle != None:   # Descarta cicles ocults (tg_id IS NULL)
>             opcions.append((cicle.codi, cicle.nom))
>     return opcions

It is difficult to judge from your code-example as it does not display the 
whole two-stage-process, but are you aware that you need to pass around *all* 
form-fields of the first form, using hidden input fields in the second one?

Alternatively, you can use the session of course.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to