[Checkins] SVN: z3c.form/trunk/src/z3c/form/ Move ``showLabel`` attribute to the browser part of MultiWidget. Mark it as overridable by attribute adapters.
Dan Korostelev
nadako at gmail.com
Tue Feb 3 20:29:22 EST 2009
Log message for revision 96054:
Move ``showLabel`` attribute to the browser part of MultiWidget. Mark it as overridable by attribute adapters.
Changed:
U z3c.form/trunk/src/z3c/form/browser/multi.py
U z3c.form/trunk/src/z3c/form/browser/multi.txt
U z3c.form/trunk/src/z3c/form/widget.py
-=-
Modified: z3c.form/trunk/src/z3c/form/browser/multi.py
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/multi.py 2009-02-04 01:13:03 UTC (rev 96053)
+++ z3c.form/trunk/src/z3c/form/browser/multi.py 2009-02-04 01:29:22 UTC (rev 96054)
@@ -28,14 +28,14 @@
from z3c.form import interfaces
from z3c.form import widget
from z3c.form import button
-from z3c.form.browser.widget import HTMLSelectWidget
+from z3c.form.browser.widget import HTMLFormElement
class FormMixin(object):
zope.interface.implements(interfaces.IButtonForm, interfaces.IHandlerForm)
-class MultiWidget(HTMLSelectWidget, widget.MultiWidget, FormMixin):
+class MultiWidget(HTMLFormElement, widget.MultiWidget, FormMixin):
"""Multi widget implementation."""
zope.interface.implements(interfaces.IMultiWidget)
@@ -45,6 +45,12 @@
klass = u'multi-widget'
items = ()
+ showLabel = True # show labels for item subwidgets or not
+
+ # Internal attributes
+ _adapterValueAttributes = widget.MultiWidget._adapterValueAttributes + \
+ ('showLabel',)
+
def updateActions(self):
self.updateAllowAddRemove()
if self.name is not None:
Modified: z3c.form/trunk/src/z3c/form/browser/multi.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/multi.txt 2009-02-04 01:13:03 UTC (rev 96053)
+++ z3c.form/trunk/src/z3c/form/browser/multi.txt 2009-02-04 01:29:22 UTC (rev 96054)
@@ -919,10 +919,12 @@
Label
-----
-There is an option which allows to disable the label for the (sub) widgets.
+There is an option which allows to disable the label for the subwidgets.
You can set the `showLabel` option to `False` which will skip rendering the
labels. Alternatively you can also register your own template for your layer
-if you like to skip the label rendering for all widgets.
+if you like to skip the label rendering for all widgets. One more way
+is to register an attribute adapter for specific field/widget/layer/etc.
+See below for an example.
>>> field = zope.schema.List(
... __name__=u'foo',
@@ -973,3 +975,66 @@
</div>
</div>
<input type="hidden" name="None.count" value="2" />
+
+We can also override the showLabel attribute value with an attribute
+adapter. We set it to False for our widget before, but the update method
+sets adapted attributes, so if we provide an attribute, it will be used
+to set the ``showLabel``. Let's see.
+
+ >>> from z3c.form.widget import StaticWidgetAttribute
+
+ >>> doShowLabel = StaticWidgetAttribute(True, widget=widget)
+ >>> zope.component.provideAdapter(doShowLabel, name="showLabel")
+
+ >>> widget.update()
+ >>> print widget.render()
+ <div class="multi-widget">
+ <div id="None-0-row" class="row">
+ <div class="label">
+ <label for="None-0">
+ <span>Ignored</span>
+ <span class="required">*</span>
+ </label>
+ </div>
+ <div class="widget">
+ <div class="multi-widget-checkbox">
+ <input type="checkbox" value="1"
+ class="multi-widget-checkbox checkbox-widget"
+ id="None-0-remove" name="None.0.remove" />
+ </div>
+ <div class="multi-widget-input"><input
+ type="text" id="None-0" name="None.0"
+ class="text-widget required int-field" value="42" />
+ </div>
+ </div>
+ </div>
+ <div id="None-1-row" class="row">
+ <div class="label">
+ <label for="None-1">
+ <span>Ignored</span>
+ <span class="required">*</span>
+ </label>
+ </div>
+ <div class="widget">
+ <div class="multi-widget-checkbox">
+ <input type="checkbox" value="1"
+ class="multi-widget-checkbox checkbox-widget"
+ id="None-1-remove" name="None.1.remove" />
+ </div>
+ <div class="multi-widget-input"><input
+ type="text" id="None-1" name="None.1"
+ class="text-widget required int-field" value="43" />
+ </div>
+ </div>
+ </div>
+ <div class="buttons">
+ <input type="submit" id="widget-buttons-add"
+ name="widget.buttons.add"
+ class="submit-widget button-field" value="Add" />
+ <input type="submit" id="widget-buttons-remove"
+ name="widget.buttons.remove"
+ class="submit-widget button-field" value="Remove selected" />
+ </div>
+ </div>
+ <input type="hidden" name="None.count" value="2" />
+
\ No newline at end of file
Modified: z3c.form/trunk/src/z3c/form/widget.py
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.py 2009-02-04 01:13:03 UTC (rev 96053)
+++ z3c.form/trunk/src/z3c/form/widget.py 2009-02-04 01:29:22 UTC (rev 96054)
@@ -245,9 +245,7 @@
allowAdding = True
allowRemoving = True
- # you set showLabel to False or use another template for disable (sub)
- # widget labels
- showLabel = True
+
widgets = None
_value = None
More information about the Checkins
mailing list