I'm trying to do a simple field matching validator for a password
field. So, I have a widget like this:
register_form = widgets.TableForm(
widgets=[
widgets.TextField(name="userId", labeltext="Desired username",
default=None, validator=UniqueUsername(not_empty=True)),
widgets.TextField(name="emailAddress", labeltext="Email
address", default=None, validator=UniqueEmailAddress(not_empty=True)),
widgets.TextField(name="displayName", labeltext="Name",
default=None, validator=validators.NotEmpty()),
widgets.PasswordField(name="password", labeltext="Password",
default=None, validator=validators.String(not_empty=True)),
widgets.PasswordField(name="password2", labeltext="Confirm
password", default=None, validator=validators.String(not_empty=True)),
],
submittext="Submit"
)
(Yes, this *does* look conspicuously like the Identity SO data.) And I
have a few methods in my controller like this:
@turbogears.expose(html="ppp_tg.templates.register")
def register(self, **kw):
return dict(title="Register", register_form=register_form)
@turbogears.expose(html="ppp_tg.templates.register",
inputform=register_form, validators={"password" :
validators.FieldsMatch("password", "password2"), "password2" :
validators.FieldsMatch("password", "password2")})
[EMAIL PROTECTED](html="ppp_tg.templates.register",
inputform=register_form)
def process_register(self, **kw):
if cherrypy.request.form_errors:
return dict(title="Register", register_form=register_form)
raise
cherrypy.HTTPRedirect(turbogears.url("/registration_successful"))
@turbogears.expose(html="ppp_tg.templates.index")
def registration_successful(self, **kw):
return dict(title="Registration Successful",
register_form=register_form)
register, obviously creates the initial form. process_register handles
the post, and registration_successful is where the browser is taken upon
success. I'm having problems with checking that the fields match. I've
tried it with a FieldsMatch validator in the widget declaration. I've
tried with only a "password" key in the validators decorator. Nothing
is working. Does anyone have an example of a FieldsMatch using
widgets? Or can someone correct my ignorance?
- jmj