diff --git a/product/ERP5Form/tests/testFields.py b/product/ERP5Form/tests/testFields.py index 5903cb2d5dbba9902eb0b1b51b770630fdde2ba0..09dd34fe8440a1637e32eb03ac017315f9b25c92 100644 --- a/product/ERP5Form/tests/testFields.py +++ b/product/ERP5Form/tests/testFields.py @@ -269,6 +269,18 @@ class TestTextAreaField(ERP5TypeTestCase): self.field = TextAreaField('test_field') self.widget = self.field.widget + def test_render_view(self): + self.field.values['default'] = 'My first Line\n&My Second Line\tfoo' + self.assertEquals('<div >My first Line<br/><br/>&My Second Line\tfoo</div>', + self.field.render_view(value=['My first Line\n', '&My Second Line\tfoo'])) + editable_mode = self.portal.REQUEST.get('editable_mode', 1) + self.portal.REQUEST.set('editable_mode', 0) + try: + self.assertEquals('<div >My first Line<br/>&My Second Line\tfoo</div>', + self.field.render(REQUEST=self.portal.REQUEST)) + finally: + self.portal.REQUEST.set('editable_mode', editable_mode) + def test_render_odt(self): self.field.values['default'] = 'My first Line\nMy Second Line\tfoo' self.assertEquals('text:line-break', diff --git a/product/Formulator/Widget.py b/product/Formulator/Widget.py index 8b24991ca56847be37d41a6376da5358b707b660..33a8bafaade9980f255fe2f8deff7098b62ca049 100644 --- a/product/Formulator/Widget.py +++ b/product/Formulator/Widget.py @@ -531,6 +531,13 @@ class TextAreaWidget(Widget): extra=field.get_value('extra')) def render_view(self, field, value, REQUEST, render_prefix=None): + if value is None: + return '' + if not isinstance(value, (tuple, list)): + value = value.split('\n') + line_separator = '<br/>' + value_list = [escape(part).replace('\n', line_separator) for part in value] + value = line_separator.join(value_list) return render_element("div", css_class=field.get_value('css_class'), contents=value,