[Zope3-Users] Re: Formlib - handleSubmit, custom validator on action

Maciej Wisniowski maciej.wisniowski at coig.katowice.pl
Thu Mar 29 09:22:34 EDT 2007


> So I am always getting an empty dictionary back to my action method.
>
> Sorry for the noise. In the meantime I've just gone back to creating an
> interface with and @interface.invariant which is working for me. I was
> just keen to find out if validator could be used.
>   
I used validation directly in action function especially because
I had some rdbms operations here. I've written a bit about this
recently. Search for
'Formlib and custom validation constraints' thread. It is something like:

Function defined in my view class eg. descendant of EditForm

    from zope.app.form.interfaces import WidgetInputError

    def setWidgetError(self, name, v):
        """ Helper function for validation purposes.
            Sets error for widget
             @name - field name
             @v - error message
        """
        w = self.widgets.get(name)
        if w:
            w._error = WidgetInputError(
              self.context.__name__, w.label, v)
        return w._error

In function used as success handler I did:

if not data['myfield']:
    error = self.setWidgetError('myfield', 'Required field is empty')
    self.errors.append(error)
    self.form_reset = False


-- 
Maciej Wisniowski


More information about the Zope3-users mailing list