diff --git a/forms/TextareaField.php b/forms/TextareaField.php
index f5ab994fa..bf2934361 100644
--- a/forms/TextareaField.php
+++ b/forms/TextareaField.php
@@ -57,24 +57,6 @@ class TextareaField extends FormField {
);
}
- function getTemplate() {
- return ($this->isReadonly()) ? "{$this->template}_readonly" : $this->template;
- }
-
- /**
- * Performs a readonly transformation on this field. You should still be
- * able to copy from this field, and it should still send when you submit
- * the form it's attached to.
- *
- * The element shouldn't be both disabled and readonly at the same time.
- */
- function performReadonlyTransformation() {
- $clone = clone $this;
- $clone->setReadonly(true);
- $clone->setDisabled(false);
- return $clone;
- }
-
/**
* Performs a disabled transformation on this field. You shouldn't be able to
* copy from this field, and it should not send any data when you submit the
diff --git a/templates/forms/FormField.ss b/templates/forms/FormField.ss
index 81f608a74..14f80289e 100644
--- a/templates/forms/FormField.ss
+++ b/templates/forms/FormField.ss
@@ -1,2 +1,5 @@
- class="$extraClass"<% end_if %>>$Value
-
+<% if isReadonly %>
+ class="$extraClass"<% end_if %>>$Value
+<% else %>
+
+<% end_if %>
diff --git a/templates/forms/TextareaField_Readonly.ss b/templates/forms/TextareaField_Readonly.ss
deleted file mode 100644
index a287b67a4..000000000
--- a/templates/forms/TextareaField_Readonly.ss
+++ /dev/null
@@ -1 +0,0 @@
-<% if Value %>$Value<% else %>(<% _t('NONE', 'none') %>)<% end_if %>
\ No newline at end of file
diff --git a/tests/forms/TextareaFieldTest.php b/tests/forms/TextareaFieldTest.php
index 589fed008..2cd07c937 100644
--- a/tests/forms/TextareaFieldTest.php
+++ b/tests/forms/TextareaFieldTest.php
@@ -6,21 +6,32 @@ class TextareaFieldTest extends SapphireTest {
* Quick smoke test to ensure that text is being encoded properly.
*/
function testTextEncoding() {
- $inputText = "This is my These are some unicodes: äöü&<>";
+ $inputText = "These are some unicodes: äöü";
$field = new TextareaField("Test", "Test");
$field->setValue($inputText);
- $this->assertContains('This is my <text>These are some unicodes: äöü&<>', $field->Field());
+ $this->assertContains('These are some unicodes: äöü', $field->Field());
}
/**
- * Quick smoke test to ensure that text is being encoded properly in readonly fields.
+ * Quick smoke test to ensure that text with unicodes is being displayed properly in readonly fields.
*/
- function testReadonlyTextEncoding() {
- $inputText = "This is my These are some unicodes: äöü&<>";
+ function testReadonlyDisplayUnicodes() {
+ $inputText = "These are some unicodes: äöü";
+ $field = new TextareaField("Test", "Test");
+ $field->setValue($inputText);
+ $field = $field->performReadonlyTransformation();
+ $this->assertContains('These are some unicodes: äöü', $field->Field());
+ }
+
+ /**
+ * Quick smoke test to ensure that text with special html chars is being displayed properly in readonly fields.
+ */
+ function testReadonlyDisplaySepcialHTML() {
+ $inputText = "These are some special chars including 'single' & \"double\" quotations";
$field = new TextareaField("Test", "Test");
$field = $field->performReadonlyTransformation();
$field->setValue($inputText);
- $this->assertContains('This is my <text>These are some unicodes: äöü&<>', $field->Field());
+ $this->assertContains('These are some special <html> chars including 'single' & "double" quotations', $field->Field());
}
}