I Ian,

Thanks for you help, Now I see now what I did wrong.

I have changed my code to this, and now everything is working fine. I  
did it that way because I wanted to have an object with everything in  
it, the form, and the methods to manage that form. Maybe it is a bad  
idea but I don't see why.

class UserCreate():
     class Schema(validators.Schema):
        ...
     class Fields(widgets.WidgetsDeclaration):
        ...
     form = None
     def createForm(self):
         if self.form is None:
             self.form = widgets.TableForm(fields=self.Fields(),
                                           validator=self.Schema(),
                                           name='user', action='save',
                                           submit_text=_("Save"),)
         return self.form


-fred-


On Aug 5, 2006, at 10:34 PM, Ian Wilson wrote:

>
> Hello,
>
> The form you use to get the error in validate() is different from the
> form you pass to the template.  I can't really explain why that is
> important ...maybe someone else could but you should probably being
> doing it differently.  I don't know why you are dynamically making the
> form, you should really move it outside of your CreateUser controller
> class and also match the validate form up with the form you pass to
> the template.  Something like this:
>
>
> class Schema...
>
> class Fields...
>
> createUserForm = widgets.TableForm(fields=Fields(),
> validator=Schema(),                                  name='user',
> action='./save', submit_text=_("Save"))
>
> class CreateUser(Controller)...
>
>     @expose(template="example.templates.SignUp")
>     def index(self, tg_errors=None):
>         if tg_errors:
>             flash(_("There was a problem with the information you  
> enter!"))
>         return dict(form=createUserForm) #MATCHED WITH VALIDATE
>
>     @expose()
>     @validate(form=createUserForm) #MATCHED WITH FROM YOU PASS TO  
> TEMPLATE
>     @error_handler(index)
>     def save(self, user_name, pass1, pass2, email_addr):
>         ## --- some more code here.
>
>         print user_name, pass1, gender
>         flash("Your infomation has been saved!")
>         raise redirect("/")
>
> -Ian
>
> On 8/5/06, Fred C <[EMAIL PROTECTED]> wrote:
>>
>>
>> Hello
>>
>> Can someone tell me why with that following code, when a form is  
>> not valid,
>> it is redisplayed without the previously entered values.
>>
>> Thanks for your help.
>>
>>
>> class UserCreate(Controller):
>>     class Schema(validators.Schema):
>>         chained_validators = [validators.FieldsMatch('pass1',  
>> 'pass2')]
>>
>>     class Fields(widgets.WidgetsList):
>>         user_name = widgets.TextField('user_name', _("Login"),
>>                                       validator=validators.NotEmpty 
>> (),
>>                                       attrs={'size':16,  
>> 'maxlength':24})
>>         pass1 = widgets.PasswordField('pass1', _("Password"),
>>                                       validator=validators.NotEmpty 
>> (),
>>                                       attrs={'size':16,  
>> 'maxlength':30})
>>         pass2 = widgets.PasswordField('pass2', _("(confirm)"),
>>                                        
>> validator=validators.UnicodeString(),
>>                                       attrs={'size':16,  
>> 'maxlength':30})
>>         email_addr = widgets.TextField('email_addr', _("Email  
>> Address"),
>>
>> validator=validators.Email(not_empty=True),
>>                                        attrs={'size':30,  
>> 'maxlength':127})
>>
>>     def createForm(self):
>>         return widgets.TableForm(fields=self.Fields(),
>> validator=self.Schema(),
>>                                  name='user',
>>                                  action='./save',
>>                                  submit_text=_("Save"))
>>
>>
>>     @expose(template="example.templates.SignUp")
>>     def index(self, tg_errors=None):
>>         if tg_errors:
>>             flash(_("There was a problem with the information you  
>> enter!"))
>>         return dict(form=self.createForm())
>>
>>     @expose()
>>     @validate(form=createForm)
>>     @error_handler(index)
>>     def save(self, user_name, pass1, pass2, email_addr):
>>         ## --- some more code here.
>>
>>         print user_name, pass1, gender
>>         flash("Your infomation has been saved!")
>>         raise redirect("/")
>>
>>
>> -fred-
>>>
>>
>
> >


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