2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-10-20 12:05:05 +02:00
|
|
|
* TextareaField creates a multi-line text field,
|
|
|
|
* allowing more data to be entered than a standard
|
|
|
|
* text field. It creates the <textarea> tag in the
|
|
|
|
* form HTML.
|
|
|
|
*
|
2010-10-15 05:55:22 +02:00
|
|
|
* <b>Usage</b>
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* new TextareaField(
|
|
|
|
* $name = "description",
|
|
|
|
* $title = "Description",
|
|
|
|
* $rows = 8,
|
|
|
|
* $cols = 3,
|
|
|
|
* $value = "This is the default description"
|
|
|
|
* );
|
|
|
|
* </code>
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class TextareaField extends FormField {
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2011-12-21 17:35:42 +01:00
|
|
|
protected $template = 'TextareaField';
|
|
|
|
|
2012-02-10 12:15:21 +01:00
|
|
|
/**
|
|
|
|
* @var Int Visible number of text lines.
|
|
|
|
*/
|
|
|
|
protected $rows = 5;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Int Width of the text area (in average character widths)
|
|
|
|
*/
|
|
|
|
protected $cols = 20;
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-10-20 12:05:05 +02:00
|
|
|
* Create a new textarea field.
|
|
|
|
*
|
2007-08-27 07:13:43 +02:00
|
|
|
* @param $name Field name
|
|
|
|
* @param $title Field title
|
|
|
|
* @param $value The current value
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-01-02 17:44:23 +01:00
|
|
|
function __construct($name, $title = null, $value = '') {
|
|
|
|
if(count(func_get_args()) > 3) Deprecation::notice('3.0', 'Use setRows() and setCols() instead of constructor arguments');
|
|
|
|
|
|
|
|
parent::__construct($name, $title, $value);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2011-12-22 13:10:57 +01:00
|
|
|
function getAttributes() {
|
|
|
|
return array_merge(
|
|
|
|
parent::getAttributes(),
|
2011-03-23 05:12:25 +01:00
|
|
|
array(
|
2011-12-22 13:10:57 +01:00
|
|
|
'rows' => $this->rows,
|
|
|
|
'cols' => $this->cols,
|
|
|
|
'value' => null,
|
|
|
|
'type' => null
|
2011-03-23 05:12:25 +01:00
|
|
|
)
|
|
|
|
);
|
2007-08-13 13:54:44 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2011-12-21 17:40:05 +01:00
|
|
|
function getTemplate() {
|
|
|
|
return ($this->isReadonly()) ? "{$this->template}_Readonly" : $this->template;
|
|
|
|
}
|
|
|
|
|
2007-08-13 13:54:44 +02:00
|
|
|
/**
|
|
|
|
* 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() {
|
2008-12-04 23:38:32 +01:00
|
|
|
$clone = clone $this;
|
|
|
|
$clone->setReadonly(true);
|
|
|
|
$clone->setDisabled(false);
|
|
|
|
return $clone;
|
2007-08-13 13:54:44 +02:00
|
|
|
}
|
2011-03-25 04:42:09 +01:00
|
|
|
|
2007-08-13 13:54:44 +02:00
|
|
|
/**
|
|
|
|
* Performs a disabled transformation on this field. You shouldn't be able to
|
2011-03-25 04:42:09 +01:00
|
|
|
* copy from this field, and it should not send any data when you submit the
|
2007-08-13 13:54:44 +02:00
|
|
|
* form it's attached to.
|
|
|
|
* The element shouldn't be both disabled and readonly at the same time.
|
|
|
|
*/
|
|
|
|
function performDisabledTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
$clone = clone $this;
|
|
|
|
$clone->setDisabled(true);
|
|
|
|
$clone->setReadonly(false);
|
|
|
|
return $clone;
|
2007-08-13 13:54:44 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2007-11-07 03:03:48 +01:00
|
|
|
function Type() {
|
2011-03-23 05:12:25 +01:00
|
|
|
return parent::Type() . ($this->readonly ? ' readonly' : '');
|
2007-11-07 03:03:48 +01:00
|
|
|
}
|
2010-10-15 04:56:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of rows in the textarea
|
|
|
|
*
|
|
|
|
* @param int
|
|
|
|
*/
|
|
|
|
function setRows($rows) {
|
|
|
|
$this->rows = $rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of columns in the textarea
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function setColumns($cols) {
|
|
|
|
$this->cols = $cols;
|
|
|
|
}
|
2011-12-22 13:10:57 +01:00
|
|
|
|
|
|
|
function Value() {
|
|
|
|
return htmlentities($this->value, ENT_COMPAT, 'UTF-8');
|
|
|
|
}
|
2010-10-15 04:56:36 +02:00
|
|
|
}
|