Feature Language Change Updates Requested RMDQ PR-6.3-dev Pending

User tests: Successful: Unsuccessful:

avatar Hackwar
Hackwar
28 Feb 2024

Summary of Changes

This PR adds validation to the text custom field. It isn't added to other field types, since the text field is the only one where this makes sense. The field options get a Validate setting with these choices:

  • Regular Expression: the whole value has to match the expression.
  • Equal to Field / Not Equal to Field: the value is compared with another custom field in the same form.

In addition, Message on Validation Failure sets the message that is shown when the value is not valid.

The validation runs in the browser and on the server with the same rules:

  • Browser: the regular expression is set as the pattern attribute of the input. The comparison uses two new handlers, equals and notequals, in Joomla's form validator. An invalid field is marked red with the message next to its label before the form is submitted.
  • Server: the existing regex, equals and notequals rules check the value again on save. The regular expression is matched against the whole value, like the HTML pattern attribute, and empty optional fields are accepted.

Smaller fixes that were needed for this:

  • The form validator now wraps pattern as ^(?:…)$ like browsers do, so a|b no longer accepts ab, and it ignores an invalid pattern instead of breaking the form.
  • The pattern attribute is now escaped in the text field layout.
  • The notequals rule ignores the field group, so the plugin passes the full path of the field to compare to (com_fields.<name>).

Testing Instructions

Use the prebuilt package of this PR, or run npm run build:js after applying it, because the form validator JavaScript changed.

  1. Content → Fields → New: Type "Text", Title "Postcode", Name postcode. Set Validate = "Regular Expression", Regular Expression = [0-9]{5}, Message on Validation Failure = Please enter 5 digits. Save & Close.
  2. Content → Articles → edit any article → Fields tab: enter abc in Postcode and click Save. Then try 123456.
  3. Enter 12345 and save.
  4. Leave Postcode empty and save.
  5. Create a second Text field "Postcode repeat" with Validate = "Equal to Field" and Field to Compare to = postcode. In an article enter 12345 / 54321 and save, then 12345 / 12345 and save.
  6. Change "Postcode repeat" to Validate = "Not Equal to Field" and repeat step 5.
  7. Repeat steps 2–3 in the frontend (log in and edit an article).
  8. Optional, to check the server-side validation: in the browser's developer tools remove the pattern attribute from the Postcode input, enter abc and save.
  9. Set Validate = "No" on both fields: any value saves.

Actual result BEFORE applying this Pull Request

The "Validate" options don't exist for text custom fields.

Expected result AFTER applying this Pull Request

  • Step 2: the article isn't saved. The Postcode field is marked red with "Please enter 5 digits" next to it.
  • Steps 3 and 4: the article saves.
  • Step 5: the first combination is marked invalid, the second one saves.
  • Step 6: the other way round.
  • Step 7: same as in the backend.
  • Step 8: the article isn't saved, and the error message "Please enter 5 digits" is shown.
  • Step 9: same as before the PR.

Thanks

A big thanks goes to @coolcat-creations (Website) who sponsored this PR.

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 Hackwar Hackwar - open - 28 Feb 2024
avatar Hackwar Hackwar - change - 28 Feb 2024
Status New ⇒ Pending
avatar joomla-cms-bot joomla-cms-bot - change - 28 Feb 2024
Category ⇒ Administration Language & Strings Front End Plugins
avatar Quy
Quy - comment - 28 Feb 2024

Close #13403?

avatar Hackwar
Hackwar - comment - 28 Feb 2024

While this PR goes into that direction, I don't think that that is solving #13403. So no, not closing that one.

avatar brianteeman
brianteeman - comment - 28 Feb 2024

In addition, a input is added to customize the error message when the validation failed.

This appears to be when ANY validation fails and not when a specific field's validation fails?

avatar Hackwar
Hackwar - comment - 28 Feb 2024

In addition, a input is added to customize the error message when the validation failed.

This appears to be when ANY validation fails and not when a specific field's validation fails?

No, the message is displayed only if this specific field fails to validate.

avatar brianteeman
brianteeman - comment - 28 Feb 2024

My comment was because I saw the following settings

image

So I assumed that you could set the message in the plugin itself. But you can not.

avatar brianteeman
brianteeman - comment - 28 Feb 2024

When you have a required field then a failed validation results in an error as shown below

image

I would expect that when you have a failed vaildation rule you would have a similar error but you dont

image

avatar brianteeman
brianteeman - comment - 28 Feb 2024

I deleted the last weird behaviour post as there was an error in my recording

avatar Hackwar
Hackwar - comment - 28 Feb 2024

Yes, you can argue that a required field and a field which failed validation should both throw a similar style error. However that is not in the scope of this PR. The behavior you are describing is the general behavior of Joomla and would have to be changed in another PR.

Regarding the overriding of plugin settings: Right now this PR is a draft for a reason. ?

avatar brianteeman
brianteeman - comment - 28 Feb 2024

The behavior you are describing is the general behavior of Joomla and would have to be changed in another PR.

well that amongst all the other issues makes it a big fail for me and definitely not something for core with this approach

avatar Hackwar Hackwar - change - 28 Feb 2024
The description was changed
avatar Hackwar Hackwar - edited - 28 Feb 2024
avatar Hackwar
Hackwar - comment - 28 Feb 2024

That however has nothing to do with this PR and is a standard behavior of Joomla so far. Be my guest to change that, but right now this is how field validation works in our core library.

avatar Hackwar Hackwar - change - 28 Feb 2024
Labels Added: Feature Language Change ?
avatar brianteeman
brianteeman - comment - 28 Feb 2024

Please follow the style guide for the language strings https://manual.joomla.org/docs/next/user-interface-text/capitalisation

avatar Hackwar
Hackwar - comment - 29 Feb 2024

Did I miss anything else regarding capitalisation?

avatar brianteeman
brianteeman - comment - 29 Feb 2024

That however has nothing to do with this PR and is a standard behavior of Joomla so far. Be my guest to change that, but right now this is how field validation works in our core library.

You are quite correct. I hadn't noticed this before as it is never used (as far as I can see) in core at the moment. The non-highlighting of the invalid fields is however an accessibility fail.

avatar coolcat-creations
coolcat-creations - comment - 29 Feb 2024

That however has nothing to do with this PR and is a standard behavior of Joomla so far. Be my guest to change that, but right now this is how field validation works in our core library.

You are quite correct. I hadn't noticed this before as it is never used (as far as I can see) in core at the moment. The non-highlighting of the invalid fields is however an accessibility fail.

Actually, that's what my report back then was about: #13403 :-)

avatar brianteeman
brianteeman - comment - 29 Feb 2024

And this PR just makes that situation worse and not better

avatar coolcat-creations
coolcat-creations - comment - 29 Feb 2024

no, its about to solve it

avatar bembelimen
bembelimen - comment - 4 Mar 2024

Hey @Hackwar I see what you try to solve here and thanks for the contribution.

Nevertheless, we should not encourage people to use text fields for everything, for URL + Tel we have the URL field, for email we should create an email custom field etc. Text should not be the jack of all trades device.

Plus all the issues Brian reported.

Conceptwise this PR needs a lot of improvement to be considered as mergeable in my opinion.

(PS: Clientside validaton would be a really nice to have, too as HTML offers this anyways)

avatar Hackwar
Hackwar - comment - 4 Mar 2024

All issues Brian has reported have either been fixed or are unrelated to this PR. Of course we can discuss if a validation error should throw a notice or an error and I'm all for an error here, but that is not the scope of this PR.

Regarding the selection of validation rules, I can definitely remove some of those again. Yes, the text field is not meant to cover everything. So I would remove email, tel and url again?

Client-side validation is also a nice-to-have, but again outside of the scope of this PR. It is something that would require a change to the Form package and not an additional field in the custom field system.

avatar brianteeman
brianteeman - comment - 4 Mar 2024

If we're going to add something then it should be done holistically and not introduce/expose issues that are left to be solved elsewhere (if ever). We have a terrible habit of merging code that is knowingly incomplete. If we are serious about accessibility then we should never merge code that is knowingly introducing accessibility issues. Accessibility is always in scope.

PS I am all in favour of form validation but it must be done right

avatar Hackwar Hackwar - change - 4 Mar 2024
Labels Added: Updates Requested RMDQ
avatar Hackwar
Hackwar - comment - 4 Mar 2024

I removed the controversial validation rules again.

avatar brianteeman
brianteeman - comment - 4 Mar 2024

Conceptwise this PR needs a lot of improvement to be considered as mergeable in my opinion.

but no changes to the conceptual approach?

avatar Hackwar
Hackwar - comment - 5 Mar 2024

#42959 changes the validation everywhere from throwing a warning to throwing an error on the server side.

I don't know how we could highlight the fields after the serverside validation.

avatar coolcat-creations
coolcat-creations - comment - 5 Mar 2024

I would say that the server validation should be always combined with the client-side?! so the field highlight is done by client-side anyway. Without client side validation, this does not make sense.

avatar Hackwar
Hackwar - comment - 5 Mar 2024

The problem is, that right now we get error messages about failed validations, but not the names of the actual fields after the server side validation. We would have to extend the errors by that field name and then somehow render that in the frontend.

avatar bembelimen
bembelimen - comment - 14 Mar 2024

Why do you need to validate on the server to comunicate to the user, when you can first validate client-side and then after submission valide server-side?

I mean, we have the "pattern" attribute für html input elements which we could use as client-side validation and the field is then marked red.

What it needs then are some improvement on the server-side validation, which should be aligned with the html5 pattern.

then we have both with little effort.

avatar brianteeman
brianteeman - comment - 14 Mar 2024

finaly someone gets it!!

avatar HLeithner
HLeithner - comment - 24 Apr 2024

This pull request has been automatically rebased to 5.2-dev.

avatar HLeithner HLeithner - change - 24 Apr 2024
Title
…
[5.1] Fields: Add validations to text custom field
[5.2] Fields: Add validations to text custom field
avatar HLeithner HLeithner - edited - 24 Apr 2024
avatar crimle crimle - test_item - 15 Jul 2024 - Tested successfully
avatar crimle
crimle - comment - 15 Jul 2024

I have tested this item ✅ successfully on e58469c


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

avatar brianteeman
brianteeman - comment - 15 Jul 2024

@crimle you have marked that you have successfully tested this. How? What where the regex you used? What were the comparisons you used

avatar crimle
crimle - comment - 16 Jul 2024

@crimle you have marked that you have successfully tested this. How? What where the regex you used? What were the comparisons you used

I successfully tested the existence of the added dropdown «Validate» and the option «Maximum lenght». Both are ok.

I did NOT test the «Regular Expression» option since I am not familiar with regular expressions. I retested this morning and had an eye on the options «Not Equal to field» and «Equal to field». They seem to have no effect. Ashes on my head, - I was not conscientious enough yesterday. Sorry!

avatar HLeithner
HLeithner - comment - 2 Sep 2024

This pull request has been automatically rebased to 5.3-dev.

avatar HLeithner HLeithner - change - 2 Sep 2024
Title
…
[5.2] Fields: Add validations to text custom field
[5.3] Fields: Add validations to text custom field
avatar HLeithner HLeithner - edited - 2 Sep 2024
avatar fgsw
fgsw - comment - 5 Sep 2024

@crimle can you open https://issues.joomla.org/tracker/joomla-cms/42911 and

  • click button "Test this"
  • mark "Not tested"

The test will not longer count as successfull.

avatar crimle crimle - test_item - 5 Sep 2024 - Not tested
avatar crimle
crimle - comment - 5 Sep 2024

I have not tested this item.


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

avatar HLeithner
HLeithner - comment - 4 Mar 2025

This pull request has been automatically rebased to 6.0-dev.

avatar HLeithner HLeithner - change - 4 Mar 2025
Title
…
[5.3] Fields: Add validations to text custom field
[6.0] Fields: Add validations to text custom field
avatar HLeithner HLeithner - edited - 4 Mar 2025
avatar HLeithner
HLeithner - comment - 31 Aug 2025

This pull request has been automatically rebased to 6.1-dev.

avatar HLeithner HLeithner - change - 31 Aug 2025
Title
…
[6.0] Fields: Add validations to text custom field
[6.1] Fields: Add validations to text custom field
avatar HLeithner HLeithner - edited - 31 Aug 2025
avatar HLeithner
HLeithner - comment - 17 Mar 2026

This pull request has been automatically rebased to 6.2-dev.

avatar HLeithner
HLeithner - comment - 6 Nov 2026

This pull request has been automatically rebased to 6.3-dev. Joomla! 6.2 is now in feature freeze.

avatar HLeithner HLeithner - change - 11 Nov 2026
Title
…
[6.1] Fields: Add validations to text custom field
[6.3] Fields: Add validations to text custom field
avatar HLeithner HLeithner - edited - 11 Nov 2026
avatar Hackwar Hackwar - change - 20 Nov 2026
Labels Added: PR-6.3-dev
Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 20 Nov 2026
Category Administration Language & Strings Front End Plugins ⇒ JavaScript Layout Administration Front End Language & Strings Plugins NPM Change
avatar Hackwar Hackwar - change - 20 Nov 2026
The description was changed
avatar Hackwar Hackwar - edited - 20 Nov 2026

Add a Comment

Login with GitHub to post a comment