Skip to content

Commit

Permalink
Support for attribute maxlength. Form field textarea. Issue #6459
Browse files Browse the repository at this point in the history
Issue #6459

The maxlength attribute specifies the maximum length (in characters) of a text area. The maxlength attribute is new for the <textarea> tag in HTML5.

Test:

- Edit /administrator/components/com_config/model/form/application.xml
- Add attribute
maxlength="25"
to field MetaDesc (or any other field of type textarea).
- Go to administrator/index.php?option=com_config > Site
- Enter text into field "Site Meta Description".
- No limitation concerning length.
- Apply patch. Try again. 25 characters maximum are possible.
  • Loading branch information
bertmert committed Mar 16, 2015
1 parent efad14c commit 7032f19
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libraries/joomla/form/fields/textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function __get($name)
{
case 'rows':
case 'columns':
case 'maxlength':
return $this->$name;
}

Expand All @@ -79,6 +80,7 @@ public function __set($name, $value)
{
case 'rows':
case 'columns':
case 'maxlength':
$this->$name = (int) $value;
break;

Expand Down Expand Up @@ -107,8 +109,9 @@ public function setup(SimpleXMLElement $element, $value, $group = null)

if ($return)
{
$this->rows = isset($this->element['rows']) ? (int) $this->element['rows'] : false;
$this->columns = isset($this->element['cols']) ? (int) $this->element['cols'] : false;
$this->rows = isset($this->element['rows']) ? (int) $this->element['rows'] : false;
$this->columns = isset($this->element['cols']) ? (int) $this->element['cols'] : false;
$this->maxlength = isset($this->element['maxlength']) ? (int) $this->element['maxlength'] : false;
}

return $return;
Expand Down Expand Up @@ -139,6 +142,7 @@ protected function getInput()
$autocomplete = $autocomplete == ' autocomplete="on"' ? '' : $autocomplete;
$autofocus = $this->autofocus ? ' autofocus' : '';
$spellcheck = $this->spellcheck ? '' : ' spellcheck="false"';
$maxlength = $this->maxlength ? ' maxlength="' . $this->maxlength . '"' : '';

// Initialize JavaScript field attributes.
$onchange = $this->onchange ? ' onchange="' . $this->onchange . '"' : '';
Expand All @@ -149,7 +153,7 @@ protected function getInput()
JHtml::_('script', 'system/html5fallback.js', false, true);

return '<textarea name="' . $this->name . '" id="' . $this->id . '"' . $columns . $rows . $class
. $hint . $disabled . $readonly . $onchange . $onclick . $required . $autocomplete . $autofocus . $spellcheck . ' >'
. $hint . $disabled . $readonly . $onchange . $onclick . $required . $autocomplete . $autofocus . $spellcheck . $maxlength . ' >'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '</textarea>';
}
}

0 comments on commit 7032f19

Please sign in to comment.