l.a.w.t.DelimitedListWidget(TextAreaWidget) : class documentation

Part of lp.app.widgets.textwidgets View In Hierarchy

A widget that represents a list as whitespace-delimited text.

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.
def __init__(self, field, value_type, request):
Undocumented
def _toFormValue(self, value):

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'
def _toFieldValue(self, value):

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']
API Documentation for Launchpad, generated by pydoctor at 2019-11-17 00:00:06.