Am 07.09.2010, 06:56 Uhr, schrieb Tim Hoffman <zutes...@gmail.com>: > So in my contrived example I would like the set of possible values > for color is dependent on the > user and some other factor. Looking at the code for SelectWidget and > RadioChoice widget > it appears they won't take a callable and lazily render those values > at render time.
Tim, do you mean in a similar way to the way a vocabulary works in zope.schema? I discussed this a while back with Chris and the reason why this often extremely useful feature isn't built into deform is that deform on its own has no context. I have written something similar - a callable that works both as a validator for Schema nodes and as values for widgets: class Source(object): """Utility for vocabulary constraints""" def __init__(self, values): """Can be initialised from a dictionary, a list of tuples or a list""" if hasattr(values, 'items'): self.values = values.items() elif hasattr(values, 'append'): try: dict(values) self.values = values except ValueError: self.values = enumerate(values) def __call__(self, value): return value in self.values def __iter__(self): return self.values.__iter__() colours = Source( ['red, blue, green'] ) class MySchema(MappingSchema): colour = SchemaNode( String(), title=u'Travel details', validator=colours) class Form(object): def __init__(self, context, request): self.context = context self.request = request form = Form(MySchema(), buttons=(u'submit',)) form['lift'].widget = widget.RadioChoiceWidget(values=colours) def __call__(self): html = self.form.render() return {'form':html} I don't know how much of this could be truly dynamic. Charlie -- Charlie Clark Managing Director Clark Consulting & Research German Office Helmholtzstr. 20 Düsseldorf D- 40215 Tel: +49-211-600-3657 Mobile: +49-178-782-6226 _______________________________________________ Repoze-dev mailing list Repoze-dev@lists.repoze.org http://lists.repoze.org/listinfo/repoze-dev