[Zope3-Users] Formlib and invariants
Florian Lindner
mailinglists at xgm.de
Wed Jul 19 16:18:33 EDT 2006
Am Mittwoch, 19. Juli 2006 03:25 schrieb Darryl Cousins:
> Hi All,
>
> I've had a bit of a struggle getting formlib error views to play nicely
> with invariants. That is the problem I have found to trouble me is in
> the zope.formlib.form.FormBase method error_views.
>
> When I use the schema:
>
> class IMemberRegisterForm(IMemberData, IMemberDetails):
> """Schema for a member register form."""
>
> new_password = Password(
> title=_("Choose a Password"),
> required=True)
>
> verify_password = Password(
> title=_("Verify Password"),
> required=True)
>
> @invariant
> def passwordsMatch(register):
> if register.new_password != register.verify_password:
> msg = _("Entered passwords do not match")
> error = ('verify_password', _("Passwords"), msg)
> raise Invalid(error)
[...]
I am not sure if I've understood you correctly, but I've solved the same
problem (raise error if passwords are not equal) this way:
class PasswordsAreNotEqual(ValidationError):
"""The passwords are not equal."""
interface.implements(IWidgetInputError)
class IRegistrationForm(interface.Interface):
"""For entering the data for registration."""
password = Password(title=u"Password",
description=u"Your password.",
required=True)
password2 = Password(title=u"Verify Password",
required=True)
@interface.invariant
def arePasswordsEqual(obj):
if obj.password != obj.password2:
raise PasswordsAreNotEqual
Hope this helps,
Florian
More information about the Zope3-users
mailing list