On Aug 23, 2006, at 6:26 PM, Alexandre Futata wrote:
> Hi! I have the following question about using htmlfill on Turbogears:
>
> "How to return the form with the data previously typed by the user,
> if errors were found by the formencode.validators()"?
>
> The main question is: validation_error() can't access valid
> submitted values, so how do I send them back to the user?
>
> Sorry for the previous newbie e-mail (incomplete...). ^_^
>
> Thanks,
>
> Alexandre
> --------------------------------
> def newForm(self):
>
> form = widgets.TableForm("FormType",
> widgets.TextField(name="number",
> label="Type an Int number:")
> action = "processForm",
> submit_text = ...
> return dict(form=form)
>
> @validate(validators={"number" : validators.Int()})
> def processForm(self, number):
>
> ...(save in the database, return ok to user)...
>
> def validation_error(self, function_name, kw, errors) #
> called by the validator
>
> ....
>
Try something like:
# You need the form instantiated only once and return the same
# instance as the one passed to "validate"
form = widgets.TableForm(
fields = [
# stick your validators in the form's fields
widgets.TextField("number", validator=validators.Int(),
label=...),
]
def newForm(self):
return dict(form=form)
# Branch to "newForm" if validation fails so the form is redisplayed
with
# previous input and errors
@error_handler(newForm)
# validate input using the form's schema
@validate(form=form)
def processForm(self, number):
# number is a int if execution reaches this point
....
http://tinyurl.com/pq67j
and
http://tinyurl.com/df57n
should help too.
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
-~----------~----~----~----~------~----~------~--~---