RTC bug PR-6.2-dev Pending

User tests: Successful: Unsuccessful:

avatar hans2103
hans2103
8 Sep 2026

Pull Request resolves #48416.

  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

FormField::getLayoutData() already exposes $validationtext (populated from the XML validationtext attribute) to every field layout under layouts/joomla/form/field/. But of the 36 files there, only text.php actually turns it into the data-validation-text HTML attribute that validate.es6.js's markInvalid() reads for the client-side "invalid" message — and even there it is marked // @TODO add a proper string here!!!. checkbox.php documents $validationtext in its docblock but never uses it. Every other field type — including several that already build their own pattern attribute for HTML5 validation (tel, date, datetime, email, url, number, ...) — has no reference to it at all.

This PR moves the translate-and-output step into FormField::renderDataAttributes(), the shared method that builds $dataAttribute and is already echoed by essentially every field layout. That makes validationtext work consistently for all field types from one place, with consistent escaping: the current text.php uses $this->escape(), while several other layouts build their data attributes via ArrayHelper::toString(), which does not escape at all. renderDataAttributes() already uses htmlspecialchars(), so centralizing here avoids that inconsistency.

The now-redundant line in text.php is removed, which also resolves its @TODO.

Backward compatibility: a field that already sets a literal data-validation-text="..." XML attribute is unaffected — the new code only fills the key when it is not already present.

Testing Instructions

Client-side validation only shows a message when a field is actually invalid at the moment you click Save. So each test below makes the field invalid on purpose. Use a literal (untranslated) validationtext string so it is obvious where the message comes from: Text::_() returns an unknown key unchanged.

The message is shown inside the field's label (a red span.form-control-feedback), not under the input. A red alert at the top of the page also says that the form can't be submitted.

Log in as a Super User so no field is disabled (disabled fields are skipped by the validator).

Test 1 – email field (most reliable)

  1. Edit administrator/components/com_contact/forms/contact.xml and add a validationtext to the email_to field:
        <field
            name="email_to"
            type="email"
            label="JGLOBAL_EMAIL"
            validate="email"
            validationtext="Custom message: please enter a valid e-mail address"
        />
  1. Go to Components → Contacts → New, fill in a Name, and go to the E-mail field (Edit Contact tab).
  2. Inspect the E-mail input: it should have data-validation-text="Custom message: please enter a valid e-mail address".
  3. Type not-an-email in the E-mail field and click Save.
  4. The form is not submitted. The E-mail label shows "Custom message: please enter a valid e-mail address".

Test 2 – calendar field

  1. Edit administrator/components/com_content/forms/article.xml and change the publish_up field. Adding required="true" is essential, because the core field is optional and an empty value would otherwise simply be valid:
        <field
            name="publish_up"
            type="calendar"
            label="COM_CONTENT_FIELD_PUBLISH_UP_LABEL"
            translateformat="true"
            showtime="true"
            filter="user_utc"
            required="true"
            validationtext="Custom message: a start publishing date is required"
        />
  1. Go to Content → Articles → New, enter a Title, and open the Publishing tab.
  2. Inspect the Start Publishing input: it should have the data-validation-text attribute and class="form-control required".
  3. Make sure the field is empty (it is empty by default on a new article; on an existing article, open the calendar popup and click Clear). Then click Save while staying on the Publishing tab.
  4. The form is not submitted. The Start Publishing label shows "Custom message: a start publishing date is required".

Test 3 – regression check for text

  1. In the same article.xml, add validationtext="Custom message: title is required" to the title field (already required="true").
  2. Content → Articles → New, leave Title empty and click Save.
  3. The Title label shows "Custom message: title is required", exactly as before the patch.

Test 4 – explicit data-validation-text still wins

  1. On the email_to field from test 1, also add data-validation-text="Explicit attribute wins".
  2. Repeat test 1. The label shows "Explicit attribute wins", not the validationtext value.

Actual result BEFORE applying this Pull Request

  • Test 1 and 2: the input has no data-validation-text attribute. On Save the label shows the generic message ("This value is not valid" for the e-mail, "Please fill in this field" for the calendar). The validationtext value is silently ignored. The same applies to every field type except text.
  • Test 3: the custom message is shown.

Expected result AFTER applying this Pull Request

  • Test 1 and 2: the input renders data-validation-text="…", and on Save the custom message is shown in the label.
  • Test 3: unchanged, the custom message is shown.
  • Test 4: the explicitly set data-validation-text is kept.

Link to documentations

Please select:

  • Documentation link for guide.joomla.org:

  • No documentation changes for guide.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar hans2103 hans2103 - open - 8 Sep 2026
avatar hans2103 hans2103 - change - 8 Sep 2026
Status New ⇒ Pending
avatar joomla-cms-bot joomla-cms-bot - change - 8 Sep 2026
Category ⇒ Layout Libraries
avatar hans2103 hans2103 - change - 8 Sep 2026
The description was changed
avatar hans2103 hans2103 - edited - 8 Sep 2026
avatar richard67
richard67 - comment - 8 Sep 2026

Testing

Verified locally on a Joomla 6.1.3 install: a calendar field with validationtext set now renders data-validation-text with the translated text and shows it as the client-side validation message; a text field's existing behaviour is unchanged.

This PR here is for the 5.4-dev branch, so it should be tested on 5.4.

avatar richard67
richard67 - comment - 8 Sep 2026

@hans2103 Please keep the structure of the description of this PR like in our pull request template, and acknowledge the Generative AI policy . Thanks in advance.

avatar hans2103 hans2103 - change - 8 Sep 2026
The description was changed
avatar hans2103 hans2103 - edited - 8 Sep 2026
avatar hans2103 hans2103 - edited - 8 Sep 2026
avatar hans2103 hans2103 - change - 8 Sep 2026
The description was changed
avatar hans2103
hans2103 - comment - 8 Sep 2026

@richard67 body text adjusted to the template

avatar hans2103 hans2103 - change - 25 Sep 2026
Labels Added: PR-5.4-dev
avatar robbiejackson robbiejackson - test_item - 29 Oct 2026 - Tested successfully
avatar robbiejackson
robbiejackson - comment - 29 Oct 2026

I have tested this item ✅ successfully on 21c9140

I tested this with several different types of fields - text, integer, number (float), list.

The number field had custom client-side validation and when invalid data was entered the validationtext language string was correctly translated and output.

For the other fields I verified that the data-validation-text attribute was set from the validationtext attribute.

If both validationtext and data-validation-text attributes are set then the data-validation-text attribute takes precedence (correct behaviour, in my view).


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48417.

avatar robbiejackson
robbiejackson - comment - 29 Oct 2026

I have tested this item ✅ successfully on 21c9140

I tested this with several different types of fields - text, integer, number (float), list.

The number field had custom client-side validation and when invalid data was entered the validationtext language string was correctly translated and output.

For the other fields I verified that the data-validation-text attribute was set from the validationtext attribute.

If both validationtext and data-validation-text attributes are set then the data-validation-text attribute takes precedence (correct behaviour, in my view).


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48417.

avatar richard67 richard67 - change - 31 Oct 2026
Title
…
Fix #48416: honour validationtext for every form field type
[6.2] Fix #48416: honour validationtext for every form field type
avatar richard67 richard67 - edited - 31 Oct 2026
avatar richard67
richard67 - comment - 31 Oct 2026

As 5.4 has reached end of bugfix support and is now in security only support mode, I've allowed myself to rebase this PR here to 6.2-dev, where bug fixes should be made now. This worked cleanly, so the previous human test is still valid.

avatar richard67 richard67 - change - 31 Oct 2026
Labels Added: bug PR-6.2-dev
Removed: PR-5.4-dev
avatar richard67 richard67 - alter_testresult - 31 Oct 2026 - robbiejackson: Tested successfully
avatar hans2103 hans2103 - change - 6 Nov 2026
The description was changed
avatar hans2103 hans2103 - edited - 6 Nov 2026
avatar brianteeman
brianteeman - comment - 6 Nov 2026
validationtext="MY_VALIDATION_MESSAGE"
data-validation-text=""

The explicitly supplied empty attribute takes precedence, because isset() returns true for an empty string.

That is arguably correct because an explicitly supplied value should take precedence. However, it is worth considering whether an empty attribute should instead allow the translated validationtext value to be used.

avatar hans2103
hans2103 - comment - 6 Nov 2026

@brianteeman thx

An empty data-validation-text isn’t a meaningful override: markInvalid() treats "" as a custom message (message !== null), so the field would show an empty feedback span instead of the default text. I’ve changed the check from isset() to empty(), so an empty attribute now falls back to the translated validationtext, while a non-empty explicit attribute still takes precedence.

Test 4 in the description now covers both cases.

avatar hans2103
hans2103 - comment - 6 Nov 2026

@brianteeman The empty() check didn't help either.

FormField::setup() stores data-* XML attributes as SimpleXMLElement objects, not as strings. empty() never considers an object empty, even when the attribute value is "". I verified this against the real FormField::setup():

XML Stored as empty() trim((string) …) === ''
data-validation-text="" SimpleXMLElement object false ❌ true ✅
no attribute – true true ✅
data-validation-text="Explicit" SimpleXMLElement object false false ✅

The check now casts the value to string before comparing:

if (!empty($this->validationtext) && trim((string) ($dataAttributes['data-validation-text'] ?? '')) === '') {
    $dataAttributes['data-validation-text'] = Text::_($this->validationtext);
}
avatar brianteeman brianteeman - test_item - 6 Nov 2026 - Tested successfully
avatar brianteeman
brianteeman - comment - 6 Nov 2026

I have tested this item ✅ successfully on 9579744


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48417.

avatar brianteeman
brianteeman - comment - 6 Nov 2026

I have tested this item ✅ successfully on 9579744


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48417.

avatar hans2103
hans2103 - comment - 6 Nov 2026

@robbiejackson would you be so kind to test again? I have added a fix which results in a reset of the Human Tests.
With a successful test of yours we're back on 2

avatar robbiejackson robbiejackson - test_item - 6 Nov 2026 - Tested successfully
avatar robbiejackson
robbiejackson - comment - 6 Nov 2026

I have tested this item ✅ successfully on 9579744

I repeated the tests, and confirm that validationtext overrides data-validation-text only if data-validation-text is an empty string, or just contains white space.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48417.

avatar robbiejackson
robbiejackson - comment - 6 Nov 2026

I have tested this item ✅ successfully on 9579744

I repeated the tests, and confirm that validationtext overrides data-validation-text only if data-validation-text is an empty string, or just contains white space.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48417.

avatar richard67 richard67 - change - 6 Nov 2026
The description was changed
Status Pending ⇒ Ready to Commit
avatar richard67
richard67 - comment - 6 Nov 2026

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48417.

avatar richard67
richard67 - comment - 6 Nov 2026

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48417.

avatar richard67 richard67 - edited - 6 Nov 2026
avatar MacJoom MacJoom - change - 7 Nov 2026
Labels Added: RTC
avatar MacJoom
MacJoom - comment - 8 Nov 2026

@hans2103 - Thank you for the PR - it looks good, but does not cover "every form field type" - date.php and datetime.php (and also color/simple.php) do not output $dataAttribute. A required field left empty would therefore still ignore validationtext. Could you include these layouts too? Otherwise you may need to change the title of the PR ;-)

Add a Comment

Login with GitHub to post a comment