On 11/03/2006, at 23:17, Robin Haswell wrote:
> Hey guys
>
> I'm having difficulty validating fieldsets. I know why this is
> wrong, I just don't know how I can
> make it work. Does anyone have any input? Cheers
>
> class AccountFields(widgets.WidgetsDeclaration):
> userId = widgets.TextField(label="Username")
> password = widgets.PasswordField(label="Password")
> emailAddress = widgets.TextField(label="E-mail address")
>
> class PersonalFields(widgets.WidgetsDeclaration):
> displayName = widgets.TextField(label="What do you like to be
> called?")
> firstname = widgets.TextField(label="First name")
> lastname = widgets.TextField(label="Last name")
>
> class RegisterForm(widgets.WidgetsDeclaration):
> account = widgets.FieldSet(legend="Account", fields=AccountFields())
> personal = widgets.FieldSet(legend="Personal",
> fields=PersonalFields())
>
> class Root(controllers.RootController):
> ...
> @turbogears.expose(html=".templates.register")
> @turbogears.validate(form=RegisterForm())
> def register(self):
> return dict(form=widgets.FieldSetForm(fields=RegisterForm(),
> submit_text="Register"))
>
> Obviously I get:
>
> AttributeError: 'RegisterForm' object has no attribute 'validate'
That's because RegisterForm() is not a form... just a list of
widgets. Try:
@turbogears.validate(form=FieldSetForm(fields=RegisterForm()))
Though you might want to instantiate somewhere else so you don't do
twice (at the validate parameters and method's return dict. Something
like
Class Controller(RootController):
def __init__(self):
self.form = FieldSetForm(...)
>
> Personally I don't think this is solvable, but I'd love to be
> proved wrong :-) Maybe I need to leave
> fieldsets until documentation is complete
That should prove you wrong ;)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---