Hi all, I have been using form validation quite often following http://docs.turbogears.org/1.0/SimpleWidgetForm but today I ran into a small problem. I have a form that contains a CheckboxList. This CheckboxList is generated from a database table (think "tags"). So I created a method called "_get_form" to generate this form (inside the Controller class).
I am aware that I can use callables inside the @validate decorator, so naturally the following works. @validate( _get_form ) @error_handler( new ) def save( self, ... ) Now, assuming that "new" is a method that simply displays the form, one would expect validation errors to show up in the generated output. However that is not the case. Am I doing something wrong? Or could this be considered to be a bug? How to reproduce: 1) Quickstart a project "testfoo" (TG 1.0.8) 2) Overwrite the contents of controllers.py with the content posted below 3) create a new template file "new.kid" with the content posted below 4) Start the application 5) Open http://localhost:8080/new2 6) enter a non-numeric value into the "Number" field and submit 7) Notice the "Please enter a Number" error message next to the "Number" field 8) Open http://localhost:8080/new 9) enter a non-numeric value into the "Number" field and submit 10) Notce that the error message is *missing*! ===== controllers.py =========== import turbogears as tg from turbogears import controllers, expose, flash, widgets, validate, validators, error_handler # from testfoo import model # import logging # log = logging.getLogger("testfoo.controllers") class Root(controllers.RootController): staticform = widgets.TableForm( fields = [ widgets.TextField(name='number', label=_('Number'), default=1, validator=validators.Number()), widgets.TextField(name='title', label=_('Title'), validator=validators.String()), ], name='newForm', submit_text=_('Save') ) def _get_form(self): return widgets.TableForm( fields = [ widgets.CheckBoxList( name="tags", label=_('Tags'), options=[ (x, `x`) for x in range(10) ]), widgets.TextField(name='number', label=_('Number'), default=1, validator=validators.Number()), widgets.TextField(name='title', label=_('Title'), validator=validators.String()), ], name='newForm', submit_text=_('Save') ) @expose(template="testfoo.templates.welcome") def index(self): import time # log.debug("Happy TurboGears Controller Responding For Duty") flash("Your application is now running") return dict(now=time.ctime()) @expose( template="testfoo.templates.new" ) def new(self, tg_errors=None): return dict( form=self._get_form(), action="save" ) @expose( template="testfoo.templates.new" ) def new2( self, tg_errors=None ): return dict( form = self.staticform, action="save2" ) @validate(_get_form) @error_handler( new ) @expose() def save(self, **kwargs): return dict( locals=`locals()` ) @validate(staticform) @error_handler( new2 ) @expose() def save2( self, **kwargs ): return dict( locals=`locals()` ) ===== new.kid =========== <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/ kid/ns#" py:extends="'master.kid'"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/> <title>Welcome to TurboGears</title> </head> <body> ${form( action=action )} </body> </html> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

