[Grok-dev] Re: how to hide a field in setUpWidgets
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Sat Jul 12 06:33:11 EDT 2008
Ivo van der Wijk wrote:
> def __init__(self, context, request):
> super(...)(context, request)
> if cond(self.request):
> self.form_fields = grok.AutoFields(..).omit('special_field')
> else:
> self.form_fields = grok.AutoFields(..)
>
> I'm still open to alternative suggestions (i.e. hiding the widget) but
> this will do the trick for now.
What about 1):
@property
def form_fields(self):
fields = grok.AutoFields(..)
if some_condition(self.request):
fields = fields.oimt('special_field')
return fields
or 2):
def update(self):
self.form_fields = fields = grok.AutoFields(..)
if some_condition(self.request):
self.form_fields = fields.omit('special_field')
Would this work for you?
I generally follow one of these patterns for dynamically filling in the
form_fields attribute on the form class. I'm still trying to find out
what reasons I have for sometimes choosing 1) and sometimes opting for
solution 2).
regards,
jw
More information about the Grok-dev
mailing list