[Grok-dev] Re: Access to widgets, actions and errors in grok forms
janwijbrand at gmail.com
Thu Jan 25 15:25:06 EST 2007
> Grok currently hides some (most) of zope.formlib's implementation by
> way of grok.Edit/Add/DisplayForm. However, when you're writing you own
> pagetemplates for rendering the form, you'd want access to
> zope.formlib.form.FormBase's errors, widgets, and actions attributes.
> For errors and widgets I can imagine this patch:
> Index: grok/components.py
> --- grok/components.py (revision 72171)
> +++ grok/components.py (working copy)
> @@ -348,6 +348,9 @@
> form = self.form
> + self.errors = form.errors
> + self.widgets = form.widgets
> + self.actions = form.actions
> # this code is extracted and modified from form.render
> However, I'm not sure about the self.actions assignment because
> formlib's action decorator is doing some sys._getframe() trickery I do
> not really understand in order to append action methods to the form
> instance's actions "attribute" (by lack of a better name, see the
> implementation in zope.formlib.form.action).
> It seems to work though. This could all be sufficient for now, but
> maybe we can come up with better ideas?
On second thought (well, actually after a short discussion with
Martijn), I realised you can also get to the form attribute on the
view in order to get to widgets/actions/errors. The default form
rendering templates in grok do this.
More information about the Grok-dev