[Zope3-Users] Cancelling AddForm

Darryl Cousins darryl at darrylcousins.net.nz
Mon Mar 12 18:17:14 EDT 2007


On Mon, 2007-03-12 at 16:18 +0100, Thierry Florac wrote:
>   Hi,
> 
> I have several formlib.form.AddForm subclasses in which I've created a
> custom Action via "@action(...)".
> My problem is that I'd like to be able to launch some of these actions
> (but not all of them, it's "action specific") without executing
> automatic formlib controls (actually, for example, even a simple
> "Cancel" button which should just redirect the browser actually raises
> an exception when required fields are missing).
> 
> Any help ?
> Thanks,
> 
>   Thierry Florac

Hi Thierry,

I implement cancel buttons for formlib like this (probably came from
somewhere but I forget where)::

def always_good(form, action, data):
    """Helper for actions - will always validate - useful for cancel
actions"""
    	return []

class MyAddForm(form.AddForm):
    @form.action(_("Cancel"), validator=always_good)
    def handle_cancel(self, action, data):
        self.request.response.redirect(self.nextURL())

Hope that helps, regards,
Darryl



More information about the Zope3-users mailing list