Ah thanks, I think Python has a little more magic in it than I realised :-) 
I've only been doing 
python got about 100 hours now, so I'm still a relative beginner - in terms of 
language capabilities 
that is :-)

One last question though (promise), is it possible to implement a custom 
validator - for example, to 
match a regular expression or to check if a value is not already in a database? 
Or maybe taking a 
more robust tact, is it possible to raise an error on an input value while a 
controllermethod is 
running? That might be a much better option as I can foresee some situations 
where I only know that 
some input is not acceptable after doing a fair amount of input. I know I could 
just flash() a 
message but having the message appear next to the field would be a lot better.

Oh and I was gonna do a TracWIki post, but I can't seem to register for an 
account. Immediately 
after I register I get slapped by an HTTP Auth which I won't accept what I just 
put in. If I just do 
a blog post on all this will someone link it up?

Cheers

-Rob

Alberto Valverde wrote:
> 
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to