[Grok-dev] Cancel button in forms

Sebastian Ware sebastian at urbantalk.se
Mon May 5 09:18:10 EDT 2008


This is not necessary. I only do:

     @grok.action('Cancel')
     def edit(self, **data):
         self.redirect(self.url(self.context))

and it works without validating input.

Mvh Sebastian

5 maj 2008 kl. 13.41 skrev Godefroid Chapelle:

> Hi all,
>
> I supposed I must have missed the simple way to have a working  
> cancel button with grok forms.
>
> In case this simple way does not exist, I suggest to integrate the  
> null_validator (taken from plone)
>
> """
> def null_validator(*args, **kwargs):
>    """A validator that doesn't validate anything.
>
>    This is somewhat lame, but if you have a "Cancel" type button that
>    won't want to validate the form, you need something like this.
>
>    @form.action(_(u"label_cancel", default=u"Cancel"),
>                 validator=null_validator,
>                 name=u'cancel')
>    """
>    return ()
>
> class AddWord(grok.AddForm):
>    grok.context(Lesson)
>    form_fields = grok.AutoFields(Word)
>
>    @grok.action('Cancel', validator=null_validator)
>    def cancel(self):
>        self.redirect(self.url(self.context))
> """
>
> -- 
> Godefroid Chapelle (aka __gotcha) http://bubblenet.be
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list