> I'd like to show a report in the root of my web site, and above it a
> form to customize the report (i.e. restrict dates and so on).
> Initially, the report is generated using default values.
>
> It works well, until I start using validators. Then, initially, the
> default values of the form are overridden by the variables of the
> request, and error messages appear all over the form.
Well... this is a feature :) Normally you'd like to inform your users of
the reason their form is not being accepted and pre-fill the values they
sent so they don't have to fill them again.
> Is it by-design hard to do this? All examples I've seen use two
> handlers for displaying the form and validating it.
You can handle the form in the same controller that displays it like this:
@validate(form=form)
@expose()
def index(self, tg_errors=None, **kw):
if tg_errors is None:
# validation succeeded, do something useful
# validation failed, let the form display errors and previous values
return(form=form, ...)
The important part is the 'tg_errors' keyword arg. It informs the
errorhandling mechanism that this method will be it's own error handler.
When validation fails inside the validate decorator it will pass the
resulting errors to your controller via that parameter.
The form will receive them magically along with previous input via
request-local storage @ cherrypy.request.
HTH,
Alberto
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---