From d3cd609e45d4c5f188e930a1ed37e0783947f878 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Fri, 1 Apr 2016 15:06:49 +0300 Subject: [PATCH] Allow HTMLFormField placeholder to be a message Change-Id: Ib135a8792dcf03fd2246c208ab4c8185caef2ac6 --- includes/htmlform/HTMLTextAreaField.php | 26 ++++++++++++++++++++-- includes/htmlform/HTMLTextField.php | 29 +++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/includes/htmlform/HTMLTextAreaField.php b/includes/htmlform/HTMLTextAreaField.php index 973f1cb8d8..8ffff43888 100644 --- a/includes/htmlform/HTMLTextAreaField.php +++ b/includes/htmlform/HTMLTextAreaField.php @@ -4,6 +4,24 @@ class HTMLTextAreaField extends HTMLFormField { const DEFAULT_COLS = 80; const DEFAULT_ROWS = 25; + protected $mPlaceholder = ''; + + /** + * @param array $params + * - cols, rows: textarea size + * - placeholder/placeholder-message: set HTML placeholder attribute + * - spellcheck: set HTML spellcheck attribute + */ + public function __construct( $params ) { + parent::__construct( $params ); + + if ( isset( $params['placeholder-message'] ) ) { + $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->parse(); + } elseif ( isset( $params['placeholder'] ) ) { + $this->mPlaceholder = $params['placeholder']; + } + } + function getCols() { return isset( $this->mParams['cols'] ) ? $this->mParams['cols'] : static::DEFAULT_COLS; } @@ -32,9 +50,11 @@ class HTMLTextAreaField extends HTMLFormField { if ( $this->mClass !== '' ) { $attribs['class'] = $this->mClass; } + if ( $this->mPlaceholder !== '' ) { + $attribs['placeholder'] = $this->mPlaceholder; + } $allowedParams = [ - 'placeholder', 'tabindex', 'disabled', 'readonly', @@ -56,9 +76,11 @@ class HTMLTextAreaField extends HTMLFormField { if ( $this->mClass !== '' ) { $attribs['classes'] = [ $this->mClass ]; } + if ( $this->mPlaceholder !== '' ) { + $attribs['placeholder'] = $this->mPlaceholder; + } $allowedParams = [ - 'placeholder', 'tabindex', 'disabled', 'readonly', diff --git a/includes/htmlform/HTMLTextField.php b/includes/htmlform/HTMLTextField.php index 4d5bcabbc8..9e8e56dca8 100644 --- a/includes/htmlform/HTMLTextField.php +++ b/includes/htmlform/HTMLTextField.php @@ -1,6 +1,27 @@ mPlaceholder = $this->getMessage( $params['placeholder-message'] )->parse(); + } elseif ( isset( $params['placeholder'] ) ) { + $this->mPlaceholder = $params['placeholder']; + } + } + function getSize() { return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45; } @@ -27,6 +48,9 @@ class HTMLTextField extends HTMLFormField { if ( $this->mClass !== '' ) { $attribs['class'] = $this->mClass; } + if ( $this->mPlaceholder !== '' ) { + $attribs['placeholder'] = $this->mPlaceholder; + } # @todo Enforce pattern, step, required, readonly on the server side as # well @@ -37,7 +61,6 @@ class HTMLTextField extends HTMLFormField { 'pattern', 'title', 'step', - 'placeholder', 'list', 'maxlength', 'tabindex', @@ -90,6 +113,9 @@ class HTMLTextField extends HTMLFormField { if ( $this->mClass !== '' ) { $attribs['classes'] = [ $this->mClass ]; } + if ( $this->mPlaceholder !== '' ) { + $attribs['placeholder'] = $this->mPlaceholder; + } # @todo Enforce pattern, step, required, readonly on the server side as # well @@ -100,7 +126,6 @@ class HTMLTextField extends HTMLFormField { 'flags', 'indicator', 'maxlength', - 'placeholder', 'readonly', 'required', 'tabindex', -- 2.20.1