mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Made use of FormField->createTag() functionality for creating a textarea field in TextareaField->Field()
MINOR Documentation tweaks in TextareaField git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64551 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
1611deb019
commit
f5a39b5c2c
@ -1,6 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Multi-line text area.
|
||||
* 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
|
||||
*/
|
||||
@ -8,7 +12,8 @@ class TextareaField extends FormField {
|
||||
protected $rows, $cols, $disabled = false, $readonly = false;
|
||||
|
||||
/**
|
||||
* Create a new multi-line text area field.
|
||||
* Create a new textarea field.
|
||||
*
|
||||
* @param $name Field name
|
||||
* @param $title Field title
|
||||
* @param $rows The number of rows
|
||||
@ -23,26 +28,35 @@ class TextareaField extends FormField {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <textarea> tag - used in templates.
|
||||
* 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() {
|
||||
$classAttr = '';
|
||||
if( $this->readonly ) {
|
||||
$classAttr .= 'class="readonly';
|
||||
if( $extraClass = trim( $this->extraClass() ) )
|
||||
$classAttr .= " $extraClass";
|
||||
$classAttr .= '"';
|
||||
if($this->readonly) {
|
||||
$attributes = array(
|
||||
'id' => $this->id(),
|
||||
'class' => 'readonly' . (trim($this->extraClass()) ? (' ' . trim($this->extraClass())) : ''),
|
||||
'name' => $this->name,
|
||||
'readonly' => 'readonly'
|
||||
);
|
||||
|
||||
return $this->createTag('span', $attributes, ($this->value ? $this->value : '<i>(not set)</i>'));
|
||||
} else {
|
||||
$attributes = array(
|
||||
'id' => $this->id(),
|
||||
'class' => (trim($this->extraClass()) ? trim($this->extraClass()) : ''),
|
||||
'name' => $this->name,
|
||||
'rows' => $this->rows,
|
||||
'cols' => $this->cols
|
||||
);
|
||||
|
||||
if($this->disabled) $attributes['disabled'] = 'disabled';
|
||||
|
||||
return $this->createTag('textarea', $attributes, $this->value);
|
||||
}
|
||||
else if( $extraClass = trim( $this->extraClass() ) )
|
||||
$classAttr .= 'class="' . $extraClass . '"';
|
||||
|
||||
$disabled = $this->disabled ? " disabled=\"disabled\"" : "";
|
||||
$readonly = $this->readonly ? " readonly=\"readonly\"" : "";
|
||||
|
||||
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>";
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user