From:

http://turbogears.org/2.0/docs/main/Validation.html

I'm able to get validation working with widgets without too much
difficulty, but, I need to write my own validation handler along with
using the FieldsMatch chained_validator which I'm having some
difficulty with.

models:

class PasswordSchema(Schema):
        oldpassword = String(not_empty=True)
        password = String(not_empty=True)
        passwordverify = String(not_empty=True)
        chained_validators = [FieldsMatch
('password','passwordverify')]

class PasswordForm(TableForm):
    action = 'passwordsave'
    class fields(WidgetsList):
      oldpassword = PasswordField(validator=NotEmpty)
      password = PasswordField(validator=NotEmpty)
      passwordverify = PasswordField(validator=NotEmpty)

controller code:

    @expose('cp.templates.template')
    def password(self, **kw):
        c.form = PasswordForm()
        return dict(value=dict(), template='form')

    #...@validate(PasswordForm(), error_handler=password)
    @validate(PasswordSchema())
    def passwordsave(self, **kw):
        if c.form_errors:
            flash("There was an error")
            print c.form_errors
        else:
            #provider.edit('clients',values=kw)
            flash("Password updated")
        redirect('password')

If I use validate(PasswordForm(), error_handler=password), errors are
correctly diagnosed and output to the rendered handler, password.
Empty values display 'Please enter a value' next to each of the
fields.

If I switch to the PasswordSchema() validation, I am able to read the
debug log and see

{'password': 'Please enter a value', 'oldpassword': 'Please enter a
value', 'passwordverify': 'Please enter a value'}

where it printed c.form_errors, however, I am not able to rerender the
password template.  If I change my validate decorator to:

@validate(PasswordSchema(), error_handler=password)

TurboGears does understand there was an error, but redisplays the
password template without having displayed the error messages.

What am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" 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-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to