Indeed, the problem is most probably with a different instance being
used, the ideal solution is to avoid such things since you're meant to
reuse the same widget instance.

In this particular case to avoid collisions between two forms displayed
inside the same page we display errors only for the form that has been
validated, Randall IIRC something like this should do the trick for
you:

     @expose(template="tgwater.planreview.templates.edit")
     def edit(self, obj, tg_errors):
         form = createPlanReviewForm()
         if tg_errors:
              cherrypy.request.validated_form = form
         return dict(project=obj, form=form)

Ciao
Michele

Kevin Dangoor wrote:
> I don't think I've personally tested the case where a different Form
> instance is used in each location. Otherwise, it seems like this
> should work. I'd say open a ticket. Something that could help a lot,
> if you have time, is to rearrange the code below into a test case
> (check out turbogears.widgets.tests.test_forms for examples). Having
> test cases makes things easy to fix and makes sure the bugs stay dead.
>
> Kevin
>
> On Jun 26, 2006, at 5:06 PM, Randall wrote:
>
> >
> > SVN 1590 with SQLA patches.
> >
> > I'm using widgets to create a form and thought that the widgets
> > automagically displayed error messages when a FormEncode validation
> > failed, but I'm getting back the form with no errors displayed.  Here
> > is what my code looks like.
> >
> > class PlanReviewSchema(validators.Schema):
> >     title = validators.String(not_empty=True)
> >
> > def createPlanReviewForm(controller=None):
> >     # some stuff
> >     form = TableForm(fields=fields, action="save", submit_text="Save",
> >                                   validator=PlanReviewSchema())
> >
> > class PlanReviewController(controllers.RootController,
> > RESTfulController):
> >
> >     # Some methods.
> >     # ...
> >
> >     @expose(template="tgwater.planreview.templates.edit")
> >     def edit(self, obj):
> >         form = createPlanReviewForm()
> >         return dict(project=obj, form=form)
> >
> >     @expose()
> >     @validate(form=createPlanReviewForm)
> >     @error_handler(edit)
> >     def save(self, project, **data):
> >         tg.flash("Changes saved!")
> >         raise tg.redirect("/")
> >
> > I purposely leave the "title" field empty so the validator fails and
> > the "edit" method gets called because it is the error_handler.  But
> > why
> > is there not an error message next to "title" on the form?
> >
> > Randall
> >
> >
> > >
>
>
> --
> Kevin Dangoor
> TurboGears / Zesty News
>
> email: [EMAIL PROTECTED]
> company: http://www.BlazingThings.com
> blog: http://www.BlueSkyOnMars.com


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to