[Product-Developers] z3c.form custom validator

cswank craig_swank at nrel.gov
Thu Oct 23 18:27:12 UTC 2008


Hello again,
I am following the doctests for z3c.form to create a custom validator for a
z3c.form.  I have a validator like this:

class MyValidator(validator.SimpleFieldValidator):
    def validate(self, value):
        super(MyValidator, self).validate(value)
        try:
            content = self.context[value]
        except KeyError:
            pass
        else:
            raise zope.interface.Invalid('This id (%s) is already in use' %
value)

and I registered it like this:

validator.WidgetValidatorDiscriminators(MyValidator,
field=IMyForm['some_field'])
zope.component.provideAdapter(MyValidator)

This validator raises an error when it is supposed to (when an existing id
has been entered).  The error does not get caught by the widget (or whatever
is supposed to catch it, I haven't figured that out yet).  Instead I get the
"We're sorry, but there seems to be an error…" message from Plone.

What am I doing wrong?

Craig
-- 
View this message in context: http://n2.nabble.com/z3c.form-custom-validator-tp1369266p1369266.html
Sent from the Product Developers mailing list archive at Nabble.com.





More information about the Product-Developers mailing list