2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Multi-line text area.
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new multi-line text area 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
|
|
|
*/
|
|
|
|
function __construct($name, $title = "", $rows = 5, $cols = 20, $value = "", $form = null) {
|
|
|
|
$this->rows = $rows;
|
|
|
|
$this->cols = $cols;
|
|
|
|
parent::__construct($name, $title, $value, $form);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a <textarea> tag - used in templates.
|
|
|
|
*/
|
|
|
|
function Field() {
|
2007-11-06 21:33:13 +01:00
|
|
|
$classAttr = '';
|
|
|
|
if( $this->readonly ) {
|
|
|
|
$classAttr .= 'class="readonly';
|
|
|
|
if( $extraClass = trim( $this->extraClass() ) )
|
|
|
|
$classAttr .= " $extraClass";
|
|
|
|
$classAttr .= '"';
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-11-06 21:33:13 +01:00
|
|
|
else if( $extraClass = trim( $this->extraClass() ) )
|
|
|
|
$classAttr .= 'class="' . $extraClass . '"';
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-08-13 13:54:44 +02:00
|
|
|
$disabled = $this->disabled ? " disabled=\"disabled\"" : "";
|
|
|
|
$readonly = $this->readonly ? " readonly=\"readonly\"" : "";
|
|
|
|
|
2007-11-07 03:03:48 +01:00
|
|
|
if( $this->readonly )
|
|
|
|
return "<span $disabled$readonly $classAttr id=\"" . $this->id() . "\" name=\"{$this->name}\" rows=\"{$this->rows}\" cols=\"{$this->cols}\">" . ( $this->value ? Convert::raw2att( $this->value ) : '<i>(not set)</i>' ) . "</span>";
|
|
|
|
else
|
|
|
|
return "<textarea $disabled$readonly $classAttr id=\"" . $this->id() . "\" name=\"{$this->name}\" rows=\"{$this->rows}\" cols=\"{$this->cols}\">".Convert::raw2att($this->value)."</textarea>";
|
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() {
|
|
|
|
$this->readonly = true;
|
|
|
|
$this->disabled = false;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
$this->disabled = true;
|
|
|
|
$this->readonly = false;
|
|
|
|
return $this;
|
|
|
|
}
|
2007-11-07 03:03:48 +01:00
|
|
|
|
|
|
|
function Type() {
|
|
|
|
return parent::Type() . ( $this->readonly ? ' readonly' : '' );
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
?>
|