[Zope3-checkins] SVN: Zope3/branches/3.2/ - Fixed bug #717: formlib
raised FormError when schema fields were$ missing
Christian Theune
ct at gocept.com
Mon Dec 11 13:25:11 EST 2006
Log message for revision 71533:
- Fixed bug #717: formlib raised FormError when schema fields were$ missing
from a request although not required.$
Changed:
U Zope3/branches/3.2/doc/CHANGES.txt
U Zope3/branches/3.2/src/zope/formlib/form.py
U Zope3/branches/3.2/src/zope/formlib/form.txt
-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt 2006-12-11 18:22:18 UTC (rev 71532)
+++ Zope3/branches/3.2/doc/CHANGES.txt 2006-12-11 18:25:10 UTC (rev 71533)
@@ -10,6 +10,9 @@
Bug fixes
+ - Fixed bug #717: formlib raised FormError when schema fields were
+ missing from a request although not required.
+
- Fixed bug #738: RestrictedPython was unable to parse
Unicode expressions correctly (as passed in from e.g. ZPTPages).
Modified: Zope3/branches/3.2/src/zope/formlib/form.py
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/form.py 2006-12-11 18:22:18 UTC (rev 71532)
+++ Zope3/branches/3.2/src/zope/formlib/form.py 2006-12-11 18:25:10 UTC (rev 71533)
@@ -316,7 +316,7 @@
name = _widgetKey(widget, form_prefix)
if not widget.hasInput():
- raise interfaces.FormError("No input", name)
+ continue
try:
data[name] = widget.getInputValue()
Modified: Zope3/branches/3.2/src/zope/formlib/form.txt
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/form.txt 2006-12-11 18:22:18 UTC (rev 71532)
+++ Zope3/branches/3.2/src/zope/formlib/form.txt 2006-12-11 18:25:10 UTC (rev 71533)
@@ -29,6 +29,7 @@
... name = schema.TextLine(title=u"Name")
... min_size = schema.Float(title=u"Minimum size")
... max_size = schema.Float(title=u"Maximum size")
+ ... color = schema.TextLine(title=u"Color", required=False)
... now = schema.Datetime(title=u"Now", readonly=True)
>>> from zope.formlib import form
@@ -38,10 +39,10 @@
This sets up a set of form fields from the interface, IOrder.
>>> len(MyForm.form_fields)
- 5
+ 6
>>> [w.__name__ for w in MyForm.form_fields]
- ['identifier', 'name', 'min_size', 'max_size', 'now']
+ ['identifier', 'name', 'min_size', 'max_size', 'color', 'now']
We can access individual form fields by name:
@@ -56,7 +57,7 @@
or by omitting fields:
>>> [w.__name__ for w in MyForm.form_fields.omit('now', 'identifier')]
- ['name', 'min_size', 'max_size']
+ ['name', 'min_size', 'max_size', 'color']
We can omit read-only fields using the omit_readonly option when
setting up the fields:
@@ -64,7 +65,7 @@
>>> class MyForm:
... form_fields = form.Fields(IOrder, omit_readonly=True)
>>> [w.__name__ for w in MyForm.form_fields]
- ['name', 'min_size', 'max_size']
+ ['name', 'min_size', 'max_size', 'color']
Getting HTML
@@ -103,7 +104,10 @@
type="text" value="" />
<input class="textType" id="form.max_size" name="form.max_size" size="10"
type="text" value="" />
+ <input class="textType" id="form.color" name="form.color" size="20"
+ type="text" value="" />
+
If the request contains any form data, that will be reflected in the
output:
@@ -115,7 +119,10 @@
type="text" value="" />
<input class="textType" id="form.max_size" name="form.max_size" size="10"
type="text" value="" />
+ <input class="textType" id="form.color" name="form.color"
+ size="20" type="text" value="" />
+
Sometimes we don't want this behavior: we want to ignore the request values,
particularly after a form has been processed and before it is drawn again.
This can be accomplished with the 'ignore_request' argument in
@@ -129,7 +136,10 @@
type="text" value="" />
<input class="textType" id="form.max_size" name="form.max_size" size="10"
type="text" value="" />
+ <input class="textType" id="form.color" name="form.color" size="20"
+ type="text" value="" />
+
Reading data
============
@@ -195,6 +205,8 @@
<input class="textType" id="form.max_size" name="form.max_size" size="10"
type="text" value="" />
<span class="error">Required input is missing.</span>
+ <input class="textType" id="form.color" name="form.color" size="20"
+ type="text" value="" />
{'name': u'bob'}
@@ -215,6 +227,8 @@
<input class="textType" id="form.max_size" name="form.max_size" size="10"
type="text" value="" />
<span class="error">Required input is missing.</span>
+ <input class="textType" id="form.color" name="form.color" size="20"
+ type="text" value="" />
{'name': u'bob'}
If we provide valid data, we'll get the data back:
@@ -228,6 +242,8 @@
type="text" value="42.0" />
<input class="textType" id="form.max_size" name="form.max_size" size="10"
type="text" value="142.0" />
+ <input class="textType" id="form.color" name="form.color" size="20"
+ type="text" value="" />
{'max_size': 142.0,
'min_size': 42.0,
'name': u'bob'}
More information about the Zope3-Checkins
mailing list