User tests: Successful: Unsuccessful:
The Max Length was printing just the NUMBER as the attribute instead of maxlength="NUMBER"
See screenshot
None
Status | New | ⇒ | Pending |
Category | ⇒ | Layout |
Labels |
Added:
?
|
@Quy , according to the textarea field layout code this will only work if the $maxlength
has the entire attribute instead of just an integer, for example, if the $maxlength = 'maxlength="1000"'
I just noticed there's no @var
documentation, but IMHO it should work just like the other variables, which contain the value only instead of the attribute_name="attribute_value"
Your PR will break the custom textarea field. See markup.
<textarea name="jform[com_fields][text-area]" id="jform_com_fields_text_area" class="form-control" maxlength=" maxlength="1000"" ></textarea>
The character count requires two attributes in the xml
maxlength="160"
charcounter="true"
@machadoug You have the same issue with rows
(4) and cols
(20) attributes displaying only the values. It is not happening in core so it must be on your end. Please provide steps/code to reproduce.
@machadoug I suspect you use the textarea layout with your own field,
because for core textarea
field the maxlength
is set in the class:
joomla-cms/libraries/src/Form/Field/TextareaField.php
Lines 180 to 189 in 3544d8b
It looks strange to me, but it works like that since ~3.7 version
I was indeed using a custom Textarea field in my extension. I was under the impression that we should use only the attribute value, not attribute="value"
. Like the onchange, onclick and autocomplete attributes.
Maybe we should include something in the code documentation explaining it's a string and not an integer?
* @var string $rows rows attribute for the field.
* @var string $cols cols attribute for the field.
* @var string $maxlength maxlength attribute for the field.
I was under the impression that we should use only the attribute value, not attribute="value". Like the onchange, onclick and autocomplete attributes.
That is correct expectation.
But I cannot say why it like that for textarea.
Would be good to fix it. Only need to care about backward compatibility here.
The fix should move this
joomla-cms/libraries/src/Form/Field/TextareaField.php
Lines 179 to 181 in 3544d8b
And in layout doing something like:
$maxlengthAttr = '';
if ($maxlengt)
{
$maxlengthAttr = is_numeric($maxlength) ? ' maxlength="' . $maxlength . '"' : $maxlength;
}
The same for rows and cols attribute.
Labels |
Added:
Information Required
|
Labels |
Removed:
Information Required
|
Category | Layout | ⇒ | Layout Libraries |
@machadoug I have added that changes to your PR
It ready for testing:
Make sure textarea field still working as before.
Labels |
Added:
?
?
Removed: ? |
This pull request has automatically rebased to 4.2-dev.
This pull requests has been automatically converted to the PSR-12 coding standard.
Labels |
Added:
PBF
?
?
Removed: ? ? |
Labels |
Added:
?
Removed: ? |
I have tested this item
Labels |
Removed:
?
|
Labels |
Added:
Conflicting Files
|
Labels |
Added:
PR-4.3-dev
?
Removed: Conflicting Files ? |
This pull request has been automatically rebased to 4.4-dev.
Labels |
Added:
bug
?
PR-4.4-dev
Removed: PR-4.3-dev ? |
Labels |
Added:
Small
Removed: ? |
Title |
|
This pull request has been automatically rebased to 5.2-dev.
Title |
|
Labels |
Added:
PR-5.2-dev
|
I have tested this item ✅ successfully on 82dc13f
Thank you for submitting this PR.
However, do we really need it?
The file /libraries/src/Form/Field/TextareaField.php
is already casting the parameters rows
, columns
and maxlength
to integers, isn't it?
public function __set($name, $value)
{
switch ($name) {
case 'rows':
case 'columns':
case 'maxlength':
$this->$name = (int) $value;
break;
case 'charcounter':
$this->charcounter = strtolower($value) === 'true';
break;
default:
parent::__set($name, $value);
}
}
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2025-01-16 17:43:56 |
Closed_By | ⇒ | rdeutz |
Just tested it with a custom field, seems to me obsolte now. Closing it. Can be reopened if I missed something
Thanks.
Status | Closed | ⇒ | New |
Closed_Date | 2025-01-16 17:43:56 | ⇒ | |
Closed_By | rdeutz | ⇒ |
Status | New | ⇒ | Pending |
This is a backward incompatible change if someone override the textarea layout for some reasons. The PR was from long time ago and he developer could easily modified his field to pass data in the required format like how we do in core. In addition, we can make a new PR to add the missing docblock for $rows, $columns and $maxlength variables and clearly state that it needs to be a string in the format attributename="value"
I have looked into it again. It is consistend (kind of) for some attributes we are setting the "attribute=value" in the fields class and for some other attibutes we do it in the layout. E.g. cols, rows, maxlenght, inputmode are set in the class while onchange, onclick are set in the layout. It would be good, if we had it done always in the same way but changing this now will break a lot of sites. So I am closing this (again).
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2025-01-18 14:33:16 |
Closed_By | ⇒ | rdeutz |
I am not able to reproduce this issue.
Created a custom text area field with maxlength value.
The markup has the maxlength attribute.