3 class HTMLTextAreaField
extends HTMLFormField
{
4 const DEFAULT_COLS
= 80;
5 const DEFAULT_ROWS
= 25;
7 protected $mPlaceholder = '';
10 * @param array $params
11 * - cols, rows: textarea size
12 * - placeholder/placeholder-message: set HTML placeholder attribute
13 * - spellcheck: set HTML spellcheck attribute
15 public function __construct( $params ) {
16 parent
::__construct( $params );
18 if ( isset( $params['placeholder-message'] ) ) {
19 $this->mPlaceholder
= $this->getMessage( $params['placeholder-message'] )->parse();
20 } elseif ( isset( $params['placeholder'] ) ) {
21 $this->mPlaceholder
= $params['placeholder'];
25 public function getCols() {
26 return isset( $this->mParams
['cols'] ) ?
$this->mParams
['cols'] : static::DEFAULT_COLS
;
29 public function getRows() {
30 return isset( $this->mParams
['rows'] ) ?
$this->mParams
['rows'] : static::DEFAULT_ROWS
;
33 public function getSpellCheck() {
34 $val = isset( $this->mParams
['spellcheck'] ) ?
$this->mParams
['spellcheck'] : null;
35 if ( is_bool( $val ) ) {
36 // "spellcheck" attribute literally requires "true" or "false" to work.
37 return $val === true ?
'true' : 'false';
42 public function getInputHTML( $value ) {
45 'cols' => $this->getCols(),
46 'rows' => $this->getRows(),
47 'spellcheck' => $this->getSpellCheck(),
48 ] +
$this->getTooltipAndAccessKey();
50 if ( $this->mClass
!== '' ) {
51 $attribs['class'] = $this->mClass
;
53 if ( $this->mPlaceholder
!== '' ) {
54 $attribs['placeholder'] = $this->mPlaceholder
;
65 $attribs +
= $this->getAttributes( $allowedParams );
66 return Html
::textarea( $this->mName
, $value, $attribs );
69 function getInputOOUI( $value ) {
70 if ( isset( $this->mParams
['cols'] ) ) {
71 throw new Exception( "OOUIHTMLForm does not support the 'cols' parameter for textareas" );
74 $attribs = $this->getTooltipAndAccessKey();
76 if ( $this->mClass
!== '' ) {
77 $attribs['classes'] = [ $this->mClass
];
79 if ( $this->mPlaceholder
!== '' ) {
80 $attribs['placeholder'] = $this->mPlaceholder
;
91 $attribs +
= OOUI\Element
::configFromHtmlAttributes(
92 $this->getAttributes( $allowedParams )
95 return new OOUI\
TextInputWidget( [
97 'name' => $this->mName
,
100 'rows' => $this->getRows(),