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-07-11 12:44:59 +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 {
|
2007-08-13 13:54:44 +02:00
|
|
|
protected $rows, $cols, $disabled = false, $readonly = false;
|
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 $rows The number of rows
|
|
|
|
* @param $cols The number of columns
|
|
|
|
* @param $value The current value
|
|
|
|
* @param $form The parent form. Auto-set when the field is placed in a form.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-08-20 06:36:45 +02:00
|
|
|
function __construct($name, $title = null, $rows = 5, $cols = 20, $value = "", $form = null) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->rows = $rows;
|
|
|
|
$this->cols = $cols;
|
|
|
|
parent::__construct($name, $title, $value, $form);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-20 12:05:05 +02:00
|
|
|
* Create the <textarea> or <span> HTML tag with the
|
|
|
|
* attributes for this instance of TextareaField. This
|
|
|
|
* makes use of {@link FormField->createTag()} functionality.
|
|
|
|
*
|
|
|
|
* @return HTML code for the textarea OR span element
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-10-20 12:32:14 +02:00
|
|
|
function Field() {
|
2008-10-20 12:05:05 +02:00
|
|
|
if($this->readonly) {
|
|
|
|
$attributes = array(
|
|
|
|
'id' => $this->id(),
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => 'readonly' . ($this->extraClass() ? $this->extraClass() : ''),
|
2008-10-20 12:05:05 +02:00
|
|
|
'name' => $this->name,
|
2008-10-20 12:54:04 +02:00
|
|
|
'tabindex' => $this->getTabIndex(),
|
2008-10-20 12:05:05 +02:00
|
|
|
'readonly' => 'readonly'
|
|
|
|
);
|
|
|
|
|
2008-10-20 12:58:31 +02:00
|
|
|
return $this->createTag(
|
|
|
|
'span',
|
|
|
|
$attributes,
|
2009-06-17 13:36:49 +02:00
|
|
|
(($this->value) ? nl2br(htmlentities($this->value, ENT_COMPAT, 'UTF-8')) : '<i>(' . _t('FormField.NONE', 'none') . ')</i>')
|
2008-10-29 04:13:38 +01:00
|
|
|
);
|
2008-10-20 12:05:05 +02:00
|
|
|
} else {
|
|
|
|
$attributes = array(
|
|
|
|
'id' => $this->id(),
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => ($this->extraClass() ? $this->extraClass() : ''),
|
2008-10-20 12:05:05 +02:00
|
|
|
'name' => $this->name,
|
|
|
|
'rows' => $this->rows,
|
|
|
|
'cols' => $this->cols
|
|
|
|
);
|
|
|
|
|
|
|
|
if($this->disabled) $attributes['disabled'] = 'disabled';
|
|
|
|
|
2009-06-17 13:36:49 +02:00
|
|
|
return $this->createTag('textarea', $attributes, htmlentities($this->value, ENT_COMPAT, 'UTF-8'));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* 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
|
|
|
}
|
2007-11-07 03:03:48 +01:00
|
|
|
|
|
|
|
function Type() {
|
|
|
|
return parent::Type() . ( $this->readonly ? ' readonly' : '' );
|
|
|
|
}
|
2010-06-03 03:08:58 +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;
|
|
|
|
}
|
|
|
|
}
|