Skip to content

Commit

Permalink
Merge branch 'tdesvenain-master', from git://github.com/tdesvenain/z3…
Browse files Browse the repository at this point in the history
…c.form.git
  • Loading branch information
agroszer committed Jun 9, 2014
2 parents c866db6 + daee02a commit e68d771
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ CHANGES
------------------

- Add DataExtractedEvent, which is thrown after data and errors are extracted
from widgets. Fixes https://github.com/zopefoundation/z3c.form/pull/18
from widgets. Fixes https://github.com/zopefoundation/z3c.form/pull/18

- Remove spaces at start and end of text field values.

- Explicitly hide span in ``orderedselect_input.pt``. This only
contains hidden inputs, but Internet Explorer 10 was showing them
Expand Down
4 changes: 4 additions & 0 deletions src/z3c/form/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
@zope.interface.implementer(interfaces.IDataConverter)
class BaseDataConverter(object):
"""A base implementation of the data converter."""

_strip_value = True # Remove spaces at start and end of text line

def __init__(self, field, widget):
self.field = field
Expand All @@ -44,6 +46,8 @@ def toWidgetValue(self, value):

def toFieldValue(self, value):
"""See interfaces.IDataConverter"""
if self._strip_value and isinstance(value, basestring):
value = value.strip()
if value == u'':
return self.field.missing_value
return self.field.fromUnicode(value)
Expand Down
13 changes: 13 additions & 0 deletions src/z3c/form/converter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ Again, the error message, is customized to the floating point:
(u'The entered value is not a valid decimal literal.', u'fff')


Text Data Converters
----------------------

Users often add empty spaces by mistake, for example when copy-pasting content
into the form.

>>> name = zope.schema.TextLine()
>>> namewidget = widget.Widget(TestRequest())
>>> conv = converter.FieldDataConverter(name, namewidget)
>>> conv.toFieldValue(u'Einstein ')
'Einstein'


Date Data Converter
-------------------

Expand Down
4 changes: 2 additions & 2 deletions src/z3c/form/subform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ Let's now have a look at cases where an error happens. If an error occurs in
the parent form, the sub-form is still submitted:

>>> request = TestRequest(form={
... 'car.widgets.model': u'Volvo\n',
... 'car.widgets.model': u'Volvo\n~',
... 'car.widgets.make': u'450',
... 'car.buttons.apply': u'Apply',
... 'owner.widgets.name': u'Stephan Richter',
Expand Down Expand Up @@ -400,7 +400,7 @@ Let's look at the rendered form:
<input type="text" id="car-widgets-model"
name="car.widgets.model"
class="text-widget required textline-field"
value="Volvo " />
value="Volvo ~" />
</div>
<div class="row">
<label for="car-widgets-make">Make</label>
Expand Down

0 comments on commit e68d771

Please sign in to comment.