Part of lp.app.widgets.textwidgets View In Hierarchy
The delimiting methods can be easily overridden to work with comma, semi-colon, or other delimiters.
Method | __init__ | Undocumented |
Method | _toFormValue | Converts a list to a newline separated string. |
Method | _toFieldValue | Convert the input string into a list. |
Converts a list to a newline separated string.
>>> from zope.publisher.browser import TestRequest >>> from zope.schema import Field >>> field = Field(__name__='foo', title=u'Foo') >>> widget = DelimitedListWidget(field, None, TestRequest())
The 'missing' value is converted to an empty string:
>>> widget._toFormValue(field.missing_value) u''
By default, lists are displayed one item on a line:
>>> names = ['fred', 'bob', 'harry'] >>> widget._toFormValue(names) u'fred\r\nbob\r\nharry'
Convert the input string into a list.
>>> from zope.publisher.browser import TestRequest >>> from zope.schema import Field >>> field = Field(__name__='foo', title=u'Foo') >>> widget = DelimitedListWidget(field, None, TestRequest())
The widget converts an empty string to the missing value:
>>> widget._toFieldValue('') == field.missing_value True
By default, lists are split by whitespace:
>>> print widget._toFieldValue(u'fred\nbob harry') [u'fred', u'bob', u'harry']