[Checkins] SVN: z3c.form/trunk/src/z3c/form/ Fixed a fairly deep
bug when a required radio or checkbox sequence
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Jun 2 11:33:38 EDT 2007
Log message for revision 76159:
Fixed a fairly deep bug when a required radio or checkbox sequence
widget does not have a value.
Changed:
U z3c.form/trunk/src/z3c/form/browser/README.txt
U z3c.form/trunk/src/z3c/form/browser/checkbox.txt
U z3c.form/trunk/src/z3c/form/browser/checkbox_input.pt
U z3c.form/trunk/src/z3c/form/browser/radio.txt
U z3c.form/trunk/src/z3c/form/browser/radio_input.pt
U z3c.form/trunk/src/z3c/form/browser/select.py
U z3c.form/trunk/src/z3c/form/converter.py
U z3c.form/trunk/src/z3c/form/converter.txt
-=-
Modified: z3c.form/trunk/src/z3c/form/browser/README.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/README.txt 2007-06-02 13:05:15 UTC (rev 76158)
+++ z3c.form/trunk/src/z3c/form/browser/README.txt 2007-06-02 15:33:38 UTC (rev 76159)
@@ -80,6 +80,7 @@
class="radioWidget" value="no" />
<span class="label">no</span>
</span>
+ <input name="bar-empty-marker" type="hidden" value="1" />
>>> widget.mode = interfaces.DISPLAY_MODE
>>> print widget.render()
@@ -104,6 +105,7 @@
class="checkBoxWidget" value="no" />
<span class="label">no</span>
</span>
+ <input name="bar-empty-marker" type="hidden" value="1" />
>>> widget.mode = interfaces.DISPLAY_MODE
>>> print widget.render()
Modified: z3c.form/trunk/src/z3c/form/browser/checkbox.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/checkbox.txt 2007-06-02 13:05:15 UTC (rev 76158)
+++ z3c.form/trunk/src/z3c/form/browser/checkbox.txt 2007-06-02 15:33:38 UTC (rev 76159)
@@ -49,9 +49,10 @@
... (zope.interface.Interface, IDefaultBrowserLayer, None, None, None),
... IPageTemplate, name='input')
-If we render the widget we get an emtpy output:
+If we render the widget we only get the empty marker:
>>> print widget.render()
+ <input name="foo-empty-marker" type="hidden" value="1" />
Let's provide some values for this widget. We can do this by defining a source
providing ITerms. This source uses descriminators wich will fit for our setup.
@@ -80,11 +81,11 @@
class="checkBoxWidget" value="no" />
<span class="label">no</span>
</span>
+ <input name="foo-empty-marker" type="hidden" value="1" />
+If we set the value for the widget to ``yes``, we can se that the checkbox
+field get rendered with a checked flag:
-If we set the value for the widget to ``yes``, we can se that the checkbox field
-get rendered with a checked flag:
-
>>> widget.value = 'yes'
>>> widget.update()
>>> print widget.render()
@@ -98,3 +99,4 @@
class="checkBoxWidget" value="no" />
<span class="label">no</span>
</span>
+ <input name="foo-empty-marker" type="hidden" value="1" />
Modified: z3c.form/trunk/src/z3c/form/browser/checkbox_input.pt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/checkbox_input.pt 2007-06-02 13:05:15 UTC (rev 76158)
+++ z3c.form/trunk/src/z3c/form/browser/checkbox_input.pt 2007-06-02 15:33:38 UTC (rev 76159)
@@ -28,3 +28,5 @@
value item/value" />
<span class="label" tal:content="item/label">Label</span>
</span>
+<input name="field-empty-marker" type="hidden" value="1"
+ tal:attributes="name string:${view/name}-empty-marker" />
Modified: z3c.form/trunk/src/z3c/form/browser/radio.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/radio.txt 2007-06-02 13:05:15 UTC (rev 76158)
+++ z3c.form/trunk/src/z3c/form/browser/radio.txt 2007-06-02 15:33:38 UTC (rev 76159)
@@ -44,9 +44,10 @@
... (zope.interface.Interface, IDefaultBrowserLayer, None, None, None),
... IPageTemplate, name='input')
-If we render the widget we get an emtpy output:
+If we render the widget we only get the empty marker:
>>> print widget.render()
+ <input name="foo-empty-marker" type="hidden" value="1" />
Let's provide some values for this widget. We can do this by defining a source
providing ITerms. This source uses descriminators wich will fit for our setup.
@@ -75,6 +76,7 @@
class="radioWidget" value="no" />
<span class="label">no</span>
</span>
+ <input name="foo-empty-marker" type="hidden" value="1" />
If we set the value for the widget to ``yes``, we can se that the radio field
get rendered with a checked flag:
@@ -91,3 +93,4 @@
class="radioWidget" value="no" />
<span class="label">no</span>
</span>
+ <input name="foo-empty-marker" type="hidden" value="1" />
Modified: z3c.form/trunk/src/z3c/form/browser/radio_input.pt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/radio_input.pt 2007-06-02 13:05:15 UTC (rev 76158)
+++ z3c.form/trunk/src/z3c/form/browser/radio_input.pt 2007-06-02 15:33:38 UTC (rev 76159)
@@ -28,3 +28,5 @@
value item/value" />
<span class="label" tal:content="item/label">Label</span>
</span>
+<input name="field-empty-marker" type="hidden" value="1"
+ tal:attributes="name string:${view/name}-empty-marker" />
Modified: z3c.form/trunk/src/z3c/form/browser/select.py
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/select.py 2007-06-02 13:05:15 UTC (rev 76158)
+++ z3c.form/trunk/src/z3c/form/browser/select.py 2007-06-02 15:33:38 UTC (rev 76159)
@@ -50,7 +50,7 @@
'id': self.id + '.novalue',
'value': self.noValueToken,
'content': self.noValueMessage,
- 'selected': self.noValueToken in self.value
+ 'selected': self.value == []
})
for count, term in enumerate(self.terms):
selected = self.isSelected(term)
Modified: z3c.form/trunk/src/z3c/form/converter.py
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.py 2007-06-02 13:05:15 UTC (rev 76158)
+++ z3c.form/trunk/src/z3c/form/converter.py 2007-06-02 15:33:38 UTC (rev 76159)
@@ -107,9 +107,9 @@
class BytesDataConverter(FieldDataConverter):
- """A special data converter for bytes, supporting also FileUpload.
-
- Since IBytes represents a file upload too, this converter can handle
+ """A special data converter for bytes, supporting also FileUpload.
+
+ Since IBytes represents a file upload too, this converter can handle
zope.publisher.browser.FileUpload object as given value.
"""
zope.component.adapts(
@@ -124,7 +124,7 @@
# By default a IBytes field is used for get a file upload widget.
# But interfaces extending IBytes do not use file upload widgets.
# Any way if we get a FileUpload object, we'll convert it.
- # We also store the additional FileUpload values on the widget
+ # We also store the additional FileUpload values on the widget
# before we loose them.
self.widget.headers = value.headers
self.widget.filename = value.filename
@@ -153,10 +153,9 @@
def toWidgetValue(self, value):
"""Convert from Python bool to HTML representation."""
widget = self.widget
- # if the value is the missing value, then the widget's "noValueToken"
- # is returned
+ # if the value is the missing value, then an empty list is produced.
if value is self.field.missing_value:
- return [widget.noValueToken]
+ return []
# Look up the term in the terms
terms = zope.component.getMultiAdapter(
(widget.context, widget.request, widget.form, self.field, widget),
@@ -166,7 +165,7 @@
def toFieldValue(self, value):
"""See interfaces.IDataConverter"""
widget = self.widget
- if value[0] == widget.noValueToken:
+ if not len(value) or value[0] == widget.noValueToken:
return self.field.missing_value
terms = zope.component.getMultiAdapter(
(widget.context, widget.request, widget.form, self.field, widget),
Modified: z3c.form/trunk/src/z3c/form/converter.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.txt 2007-06-02 13:05:15 UTC (rev 76158)
+++ z3c.form/trunk/src/z3c/form/converter.txt 2007-06-02 15:33:38 UTC (rev 76159)
@@ -280,20 +280,27 @@
>>> sdv.toFieldValue(['m'])
0
-Sometimes a field is not required. In those cases, the value can be the
-missing value of the field:
+Sometimes a field is not required. In those cases, the internalvalue is the
+missing value of the field. The converter interprets that as no value being
+selected:
>>> gender.missing_value = 'missing'
>>> sdv.toWidgetValue(gender.missing_value)
- ['--NOVALUE--']
+ []
-Similarly, if "no value" has been specified in the widget, the missing value
+If "no value" has been specified in the widget, the missing value
of the field is returned:
>>> sdv.toFieldValue([u'--NOVALUE--'])
'missing'
+An empty list will also cause the missing value to be returned:
+
+ >>> sdv.toFieldValue([])
+ 'missing'
+
+
Collection Sequence Data Converter
----------------------------------
More information about the Checkins
mailing list