[Checkins] SVN: z3c.form/trunk/ Allow overriding the "required" widget attribute using IValue adapter just like it's done for "label" and "name" attributes.
Dan Korostelev
nadako at gmail.com
Fri Sep 19 09:54:33 EDT 2008
Log message for revision 91268:
Allow overriding the "required" widget attribute using IValue adapter just like it's done for "label" and "name" attributes.
Changed:
U z3c.form/trunk/CHANGES.txt
U z3c.form/trunk/src/z3c/form/widget.py
U z3c.form/trunk/src/z3c/form/widget.txt
-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt 2008-09-19 13:52:02 UTC (rev 91267)
+++ z3c.form/trunk/CHANGES.txt 2008-09-19 13:54:32 UTC (rev 91268)
@@ -5,6 +5,9 @@
Version 2.0.0 (2008-??-??)
--------------------------
+- Feature: Allow overriding the "required" widget attribute using IValue adapter
+ just like it's done for "label" and "name" attributes.
+
- Refactoring: Use the ``z3c.pt.compat`` template engine compatibility
layer.
Modified: z3c.form/trunk/src/z3c/form/widget.py
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.py 2008-09-19 13:52:02 UTC (rev 91267)
+++ z3c.form/trunk/src/z3c/form/widget.py 2008-09-19 13:54:32 UTC (rev 91268)
@@ -65,7 +65,7 @@
field = None
# Internal attributes
- _adapterValueAttributes = ('label', 'name')
+ _adapterValueAttributes = ('label', 'name', 'required')
def __init__(self, request):
self.request = request
Modified: z3c.form/trunk/src/z3c/form/widget.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.txt 2008-09-19 13:52:02 UTC (rev 91267)
+++ z3c.form/trunk/src/z3c/form/widget.txt 2008-09-19 13:54:32 UTC (rev 91268)
@@ -351,12 +351,31 @@
sub-class are other options you might want to consider. Furthermore, you
could also create a computed attribute value or implement your own component.
-Overriding any other attribtue, such as ``required``, is done in the same
+Overriding other attributes, such as ``required``, is done in the same
way. If any widget provides new attributes, they are also overridable this
way. For example, the selection widget defines a label for the option that no
value was selected. We often want to override this, because the German
-translation sucks or the wording is often too generic.
+translation sucks or the wording is often too generic. Widget implementation
+should add names of overridable attributes to their "_adapterValueAttributes"
+internal attribute.
+Let's try to override the ``required`` attribute. By default the widget is required,
+because the field is required as well:
+
+ >>> ageWidget.required
+ True
+
+Let's provide a static widget attribute adapter with name "required":
+
+ >>> AgeNotRequired = widget.StaticWidgetAttribute(False, field=ageField)
+ >>> zope.component.provideAdapter(AgeNotRequired, name="required")
+
+Now, let's check if it works:
+
+ >>> ageWidget.update()
+ >>> ageWidget.required
+ False
+
Overriding the default value is somewhat special due to the complexity of
obtaining the value. So let's register one now:
More information about the Checkins
mailing list