mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
0a5f4de51c
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@76661 467b73ca-7a2a-4603-9d3b-597d59a354a9
97 lines
2.8 KiB
PHP
Executable File
97 lines
2.8 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* 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.
|
|
*
|
|
* @package forms
|
|
* @subpackage fields-basic
|
|
*/
|
|
class TextareaField extends FormField {
|
|
protected $rows, $cols, $disabled = false, $readonly = false;
|
|
|
|
/**
|
|
* Create a new textarea field.
|
|
*
|
|
* @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.
|
|
*/
|
|
function __construct($name, $title = null, $rows = 5, $cols = 20, $value = "", $form = null) {
|
|
$this->rows = $rows;
|
|
$this->cols = $cols;
|
|
parent::__construct($name, $title, $value, $form);
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
function Field() {
|
|
if($this->readonly) {
|
|
$attributes = array(
|
|
'id' => $this->id(),
|
|
'class' => 'readonly' . ($this->extraClass() ? $this->extraClass() : ''),
|
|
'name' => $this->name,
|
|
'tabindex' => $this->getTabIndex(),
|
|
'readonly' => 'readonly'
|
|
);
|
|
|
|
return $this->createTag(
|
|
'span',
|
|
$attributes,
|
|
($this->value) ? Convert::raw2xml($this->value) : '<i>(' . _t('FormField.NONE', 'none') . ')</i>'
|
|
);
|
|
} else {
|
|
$attributes = array(
|
|
'id' => $this->id(),
|
|
'class' => ($this->extraClass() ? $this->extraClass() : ''),
|
|
'name' => $this->name,
|
|
'rows' => $this->rows,
|
|
'cols' => $this->cols
|
|
);
|
|
|
|
if($this->disabled) $attributes['disabled'] = 'disabled';
|
|
|
|
return $this->createTag('textarea', $attributes, Convert::raw2xml($this->value));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
* form it's attached to.
|
|
* The element shouldn't be both disabled and readonly at the same time.
|
|
*/
|
|
function performDisabledTransformation() {
|
|
$clone = clone $this;
|
|
$clone->setDisabled(true);
|
|
$clone->setReadonly(false);
|
|
return $clone;
|
|
}
|
|
|
|
function Type() {
|
|
return parent::Type() . ( $this->readonly ? ' readonly' : '' );
|
|
}
|
|
}
|
|
?>
|