On Jul 9, 7:53 pm, Jorge Godoy <[EMAIL PROTECTED]> wrote:
> > And have these displayed in a table format then returned as an indexed
> > dict so I can reference foo['fname'] and get the value that was
> > provided.
>
> That's how widgets works.
>
> Take a look at their documentation.

Ok, I think that has helped move me a long a bit, thanks.

To try to be clearer, what I want to have is a dict of fields in the
form that is loaded from an external source at runtime.

I want to take this dict and create the form elements. Now I think I
can get this working with widgets and can definitely do it in more
straighforward way (by emitting the proper HTML myself). What I don't
know is how I can get validation working.

What I've done so far is create an __init__ in my Root class that
creates the fields and the form.

I can't figure out how to declare that form as an @validate() though.
I keep getting an error that the form name is undefined.

Briefly, the code looks like:

class Root(controllers.RootController):

    def __init__ (self):
        myfields=[]
 
myfields.append(widgets.TextField(name="username",label="Login:",
validator=validators.NotEmpty()))
        myfields.append(widgets.TextField(name="cn",label="Full
Name:"))
        self.example_form = widgets.TableForm(
            fields=myfields,
            submit_text="Create user",
            action="save"
        )
...
...
    @expose()
    def add(self, tg_errors=None, **kw):

        if tg_errors:
            turbogears.flash("There was a problem with the form!")

        return dict(form=self.example_form)

    @expose()
    @validate(form=example_form)
    @error_handler(adduser)
    def save(self, **kw):

Upon startup I get the error:

Traceback (most recent call last):
  File "./start-wiki20.py", line 23, in ?
    from wiki20.controllers import Root
  File "/home/rcrit/redhat/Wiki-20/wiki20/controllers.py", line 24,
in ?
    class Root(controllers.RootController):
  File "/home/rcrit/redhat/Wiki-20/wiki20/controllers.py", line 94, in
Root
    @expose()
NameError: name 'example_form' is not defined


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