############################################################################## # # Copyright (c) 2001, 2002 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Custom Widgets for the rotterdam layer. $Id: editingwidgets.py 70836 2006-10-20 07:30:46Z baijum $ """ from zope.interface import implements from zope.app.form.interfaces import IInputWidget from zope.app.form.browser import TextAreaWidget from zope.app.form.browser.widget import renderElement from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile class SimpleEditingWidget(TextAreaWidget): """Improved textarea editing, with async saving using JavaScript. 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 = SimpleEditingWidget(field, request) >>> widget.style = '' >>> widget.hasInput() True >>> widget.getInputValue() u'Hello\\nworld!' >>> def normalize(s): ... return '\\n '.join(filter(None, s.split(' '))) >>> print normalize( widget() ) >>> print normalize( widget.hidden() ) Calling `setRenderedValue` will change what gets output: >>> widget.setRenderedValue("Hey\\ndude!") >>> print normalize( widget() ) Check that HTML is correctly encoded and decoded: >>> request = TestRequest( ... form={'field.foo': u'