Just one typo in the code... the @validator should read
@validator(form=form) NOT @validator(form=modelling_form)

If possible could you also paste the form code with the template code?

Thanks!

On 13 Jun, 10:42, [EMAIL PROTECTED] wrote:
> It took me a short while as well to figure out how it works. The
> problem is that you need an _instance_ of the form in your class that
> you can pass to to the @validate decorator, a class def as shown in
> some of the tutorials is not enough. This also means that you cannot
> set values in the form within the script, but there is a very easy and
> handy way to do that in the template. I'll post a code snippet later
> today.
>
> On 13 jun, 08:43, "Tjaart de Beer" <[EMAIL PROTECTED]> wrote:
>
> > Hi
>
> > I have a problem with form validation not working. Here is the setup.
>
> > I have generic methods in controllers.py called view and model_view.
> > The appropriate method (either method X which displays the form, or
> > method Y which handles the form input) located in a sub_controllers.py
> > is then decided on by dispatch.
>
> > Here is my code for the form:
>
> > class ModellingFields(widgets.WidgetsList):
> >     template = widgets.TextField(validator = validators.NotEmpty(),
> > label = "Template")
> >     target = widgets.TextField(validator = validators.NotEmpty(),
> > label = "Target")
> >     program = widgets.TextField(validator = validators.NotEmpty(),
> > label = "program:")
>
> > form = widgets.TableForm(fields = ModellingFields(),submit_text = "Submit")
>
> > Method X which displays the form:
>
> > @generics.view.when("viewtype.startswith('modelling')")
> > def X(sid,viewtype,tg_errors=None):
>
> >     if tg_errors:
> >         print tg_errors, "********************************************"
> >     submit_action = "model_view?viewtype=modelling_result"
> >     return 
> > dict(tg_template=".templates.modelling",sid=sid,form=modelling_form,
> > action=submit_action,tg_errors=tg_errors)
>
> > Method Y which should handle the validation and if correct proceed:
>
> > @validate(form=modelling_form)
> > @error_handler(X)
> > @generics.model_view.when("viewtype == 'modelling_result'")
> > def Y(viewtype, target, template, program,**kwargs):
> >     result = modelling.modelling(target, template, program)
> >     return dict(tg_template=".templates.modelling_results", result = result)
>
> > Code for the generic function which dispatches it:
>
> >     @expose()
> >     def view(self, sid="",viewtype=""):
> >         try:
> >             return generics.view(sid,viewtype)
> >         except dispatch.interfaces.NoApplicableMethods:
> >             return dict(tg_template=".templates.missing_record",sid=sid)
>
> >     @expose()
> >     def model_view(self, viewtype, target, program, template):
> >         try:
> >             return generics.model_view(viewtype, target, template, program)
> >         except dispatch.interfaces.NoApplicableMethods:
> >             return dict(tg_template=".templates.missing_record",sid="")
>
> > I followed the example in the Turbogears book as well as numerous
> > tutorials on the web but I simply do not get any validation. I just
> > want the same form to be redisplayed if one of the fields are empty
> > and a warning next to the form.
>
> > Is the problem because I use dispatch?
>
> > Any help would be appreciated. Thanks!
> > --
> > Tjaart de Beer


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