[Checkins] SVN: z3c.form/trunk/src/z3c/form/widget. switch subwidget modes on main widget mode switch
Adam Groszer
agroszer at gmail.com
Sun Apr 5 12:03:37 EDT 2009
Log message for revision 98880:
switch subwidget modes on main widget mode switch
Changed:
U z3c.form/trunk/src/z3c/form/widget.py
U z3c.form/trunk/src/z3c/form/widget.txt
-=-
Modified: z3c.form/trunk/src/z3c/form/widget.py
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.py 2009-04-05 15:29:02 UTC (rev 98879)
+++ z3c.form/trunk/src/z3c/form/widget.py 2009-04-05 16:03:37 UTC (rev 98880)
@@ -249,6 +249,8 @@
widgets = None
_value = None
+ _mode = FieldProperty(interfaces.IWidget['mode'])
+
def __init__(self, request):
super(MultiWidget, self).__init__(request)
self.widgets = []
@@ -265,6 +267,18 @@
return '<input type="hidden" name="%s" value="%d" />' % (
self.counterName, len(self.widgets))
+ @apply
+ def mode():
+ """This invokes updateWidgets on any value change e.g. update/extract."""
+ def get(self):
+ return self._mode
+ def set(self, mode):
+ self._mode = mode
+ # ensure that we apply the new mode to the widgets
+ for w in self.widgets:
+ w.mode = mode
+ return property(get, set)
+
def getWidget(self, idx):
"""Setup widget based on index id with or without value."""
valueType = self.field.value_type
Modified: z3c.form/trunk/src/z3c/form/widget.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.txt 2009-04-05 15:29:02 UTC (rev 98879)
+++ z3c.form/trunk/src/z3c/form/widget.txt 2009-04-05 16:03:37 UTC (rev 98880)
@@ -588,7 +588,7 @@
>>> multiWidget.value
[u'42', u'43']
-Each widget normaly gets first process by it's update method call after
+Each widget normaly gets first processed by it's update method call after
intialization. This update call forces to call extract, which first will get
the right amount of (sub) widgets by the given counter value. Based on that
counter value the right amount of widgets will get created. Each widget will
@@ -617,7 +617,7 @@
>>> multiWidget.widgets[0].value
u'42'
-
+
>>> multiWidget.widgets[1].value
u'43'
@@ -679,6 +679,21 @@
>>> multiWidget.allowAdding, multiWidget.allowRemoving
(False, True)
+I know a guy who once switched widget mode in the middle. All simple widgets
+are easy to hack, but multiWidget needs to update all subwidgets:
+
+ >>> [w.mode for w in multiWidget.widgets]
+ ['input', 'input', 'input', 'input', 'input', 'input']
+
+Switch the multiWidget mode:
+
+ >>> multiWidget.mode = interfaces.DISPLAY_MODE
+
+Yes, all subwigets switch mode:
+
+ >>> [w.mode for w in multiWidget.widgets]
+ ['display', 'display', 'display', 'display', 'display', 'display']
+
Widget Events
-------------
More information about the Checkins
mailing list