Text widget.
Single-line text (unicode) input
>>> from zope.publisher.browser import TestRequest >>> from zope.schema import TextLine >>> field = TextLine(__name__='foo', title=u'on') >>> request = TestRequest(form={'field.foo': u'Bob'}) >>> widget = TextWidget(field, request) >>> widget.hasInput() True >>> widget.getInputValue() u'Bob'
>>> def normalize(s): ... return '\n '.join(filter(None, s.split(' ')))
>>> print normalize( widget() ) <input class="textType" id="field.foo" name="field.foo" size="20" type="text" value="Bob" />
>>> print normalize( widget.hidden() ) <input class="hiddenType" id="field.foo" name="field.foo" type="hidden" value="Bob" />
Calling setRenderedValue will change what gets output:
>>> widget.setRenderedValue("Barry") >>> print normalize( widget() ) <input class="textType" id="field.foo" name="field.foo" size="20" type="text" value="Barry" />
Check that HTML is correctly encoded and decoded:
>>> request = TestRequest( ... form={'field.foo': u'<h1>©</h1>'}) >>> widget = TextWidget(field, request) >>> widget.getInputValue() u'<h1>©</h1>'
>>> print normalize( widget() ) <input class="textType" id="field.foo" name="field.foo" size="20" type="text" value="<h1>&copy;</h1>" />
convert_missing_value
(type:
bool
)
True
cssClass
(type:
unicode
)
u''
default
(type:
str
)
''
displayMaxWidth
(type:
str
)
''
displayWidth
(type:
int
)
20
extra
(type:
str
)
''
style
(type:
str
)
''
tag
(type:
unicode
)
u'input'
type
(type:
unicode
)
u'text'
visible
(type:
bool
)
True
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)