[Zope3-Users] custom tuple widget
Marco Mariani
marco at sferacarta.com
Wed Mar 29 05:46:44 EST 2006
I'd like to create a custom widget for the "Starbucks problem" - my
designation - where I need to set an attribute to a path of an external
tree, which is stored on LDAP or DBMS.
Basically, the content object has an attribute "store" which is a tuple
of (state, city, store_no) and I would manipulate the tuple as a single
widget, with three <select> menus.
I'm thinking of declaring it this way:
== interfaces.py ==
class IMyObject(Interface):
store = Tuple(
title=u"Store",
description=u"Store state, city and number",
required = False,
min_length = 3,
max_length = 3,
value_type=TextLine(title=u"path element")
)
...
== browser/configure.py ==
<addform
label = "New MyObject"
name = "AddMyObject.html"
schema = "myapp.interfaces.IMyObject"
content_factory = "myapp.myobject.MyObject"
fields = "store"
permission = "zope.ManageContent">
<widget field="store" class=".widget.StarbucksWidget" />
</addform>
...
== browser/widget.py ==
class StarbucksWidget(TupleSequenceWidget):
....
The custom widget will then render all the tree in a javascript object
(dictionary of dictionaries of dictionaries) which will fill and change
the dropdown menus accordingly. As an improvement, the tree nodes can be
retrieved by XmlHttp
Before hitting my head too hard, is this doable?
Is it possible to avoid the bunch of javascript by having the widget
re-submit itself at each menu selection? For instance, I select the
state, the form resubmits and gives me the choice of cities. How can I
tell the first two <select> tags to reload the page? Is it enough to
attach an onchange event that calls submit() ?
Thanks
More information about the Zope3-users
mailing list