1 <?php
2 3 4 5 6 7 8 9 10
11 class TextareaField extends FormField {
12 protected $rows, $cols, $disabled = false, $readonly = false;
13
14 15 16 17 18 19 20 21 22 23
24 function __construct($name, $title = null, $rows = 5, $cols = 20, $value = "", $form = null) {
25 $this->rows = $rows;
26 $this->cols = $cols;
27 parent::__construct($name, $title, $value, $form);
28 }
29
30 31 32 33 34 35 36
37 function Field() {
38 if($this->readonly) {
39 $attributes = array(
40 'id' => $this->id(),
41 'class' => 'readonly' . ($this->extraClass() ? $this->extraClass() : ''),
42 'name' => $this->name,
43 'tabindex' => $this->getTabIndex(),
44 'readonly' => 'readonly'
45 );
46
47 return $this->createTag(
48 'span',
49 $attributes,
50 (($this->value) ? nl2br(htmlentities($this->value, ENT_COMPAT, 'UTF-8')) : '<i>(' . _t('FormField.NONE', 'none') . ')</i>')
51 );
52 } else {
53 $attributes = array(
54 'id' => $this->id(),
55 'class' => ($this->extraClass() ? $this->extraClass() : ''),
56 'name' => $this->name,
57 'rows' => $this->rows,
58 'cols' => $this->cols
59 );
60
61 if($this->disabled) $attributes['disabled'] = 'disabled';
62
63 return $this->createTag('textarea', $attributes, htmlentities($this->value, ENT_COMPAT, 'UTF-8'));
64 }
65 }
66
67 68 69 70 71 72
73 function performReadonlyTransformation() {
74 $clone = clone $this;
75 $clone->setReadonly(true);
76 $clone->setDisabled(false);
77 return $clone;
78 }
79
80 81 82 83 84 85
86 function performDisabledTransformation() {
87 $clone = clone $this;
88 $clone->setDisabled(true);
89 $clone->setReadonly(false);
90 return $clone;
91 }
92
93 function Type() {
94 return parent::Type() . ( $this->readonly ? ' readonly' : '' );
95 }
96
97 98 99 100 101
102 function setRows($rows) {
103 $this->rows = $rows;
104 }
105
106 107 108 109 110
111 function setColumns($cols) {
112 $this->cols = $cols;
113 }
114 }
115 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-