TextArea widget.
Multi-line text (unicode) input.
>>> from zope.publisher.browser import TestRequest >>> from zope.schema import Text >>> field = Text(__name__='foo', title=u'on') >>> request = TestRequest(form={'field.foo': u'Hello\r\nworld!'}) >>> widget = TextAreaWidget(field, request) >>> widget.hasInput() True >>> widget.getInputValue() u'Hello\nworld!'
>>> def normalize(s): ... return '\n '.join(filter(None, s.split(' ')))
>>> print normalize( widget() ) <textarea cols="60" id="field.foo" name="field.foo" rows="15" >Hello world!</textarea>
>>> print normalize( widget.hidden() ) <input class="hiddenType" id="field.foo" name="field.foo" type="hidden" value="Hello world!" />
Calling setRenderedValue will change what gets output:
>>> widget.setRenderedValue("Hey\ndude!") >>> print normalize( widget() ) <textarea cols="60" id="field.foo" name="field.foo" rows="15" >Hey dude!</textarea>
Check that HTML is correctly encoded and decoded:
>>> request = TestRequest( ... form={'field.foo': u'<h1>©</h1>'}) >>> widget = TextAreaWidget(field, request) >>> widget.getInputValue() u'<h1>©</h1>'
>>> print normalize( widget() ) <textarea cols="60" id="field.foo" name="field.foo" rows="15" ><h1>&copy;</h1></textarea>
There was a but which caused the content of <textarea> tags not to be rendered correctly when there was a conversion error. Make sure the quoting works correctly:
>>> from zope.schema import Text >>> field = Text(__name__='description', title=u'Description')
>>> from zope.app.form.interfaces import ConversionError >>> class TestTextAreaWidget(TextAreaWidget): ... def _toFieldValue(self, input): ... if 'foo' in input: ... raise ConversionError("I don't like foo.") ... return input ...
>>> request = TestRequest(form={'field.description': u'<p>bar</p>'}) >>> widget = TestTextAreaWidget(field, request) >>> widget.getInputValue() u'<p>bar</p>' >>> print normalize( widget() ) <textarea cols="60" id="field.description" name="field.description" rows="15" ><p>bar</p></textarea>
>>> request = TestRequest(form={'field.description': u'<p>foo</p>'}) >>> widget = TestTextAreaWidget(field, request) >>> try: ... widget.getInputValue() ... except ConversionError, error: ... print error.doc() I don't like foo. >>> print normalize( widget() ) <textarea cols="60" id="field.description" name="field.description" rows="15" ><p>foo</p></textarea>
cssClass
(type:
unicode
)
u''
default
(type:
str
)
''
extra
(type:
str
)
''
height
(type:
int
)
15
style
(type:
str
)
''
tag
(type:
unicode
)
u'input'
type
(type:
unicode
)
u'text'
visible
(type:
bool
)
True
width
(type:
int
)
60
hint(...)
label(...)
applyChanges(content)
error()
getInputValue()
hasInput()
See IWidget.hasInput.
Returns True if the submitted request form contains a value for the widget, otherwise returns False.
Some browser widgets may need to implement a more sophisticated test for input. E.g. checkbox values are not supplied in submitted forms when their value is 'off' -- in this case the widget will need to add a hidden element to signal its presence in the form.
hasValidInput()
hidden()
setPrefix(prefix)
setRenderedValue(value)