Skip to content

[6.0] Fields: Add validations to text custom field #42911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: 6.0-dev
Choose a base branch
from

Conversation

Hackwar
Copy link
Member

@Hackwar Hackwar commented Feb 28, 2024

Summary of Changes

This PR adds serverside validation to the text custom field. It doesn't add it to any other field since the text field is the only one where this makes sense. You get the validation rules which are part of the libraries folder together with conditional fields available to configure them where usefull. In addition, a input is added to customize the error message when the validation failed.

Testing Instructions

Create a custom field of type text and play around with the validation option which this adds. Test inputs in the frontend.

Thanks

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

Link to documentations

Documentation is going to be provided soon.
Please select:

@Quy
Copy link
Contributor

Quy commented Feb 28, 2024

Close #13403?

@Hackwar
Copy link
Member Author

Hackwar commented Feb 28, 2024

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

@brianteeman
Copy link
Contributor

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?

@Hackwar
Copy link
Member Author

Hackwar commented Feb 28, 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.

@brianteeman
Copy link
Contributor

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.

@brianteeman
Copy link
Contributor

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

@brianteeman
Copy link
Contributor

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

@Hackwar
Copy link
Member Author

Hackwar commented Feb 28, 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. 😉

@brianteeman
Copy link
Contributor

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

@Hackwar
Copy link
Member Author

Hackwar commented Feb 28, 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.

@Hackwar Hackwar marked this pull request as ready for review February 28, 2024 21:20
@brianteeman
Copy link
Contributor

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

@Hackwar
Copy link
Member Author

Hackwar commented Feb 29, 2024

Did I miss anything else regarding capitalisation?

@brianteeman
Copy link
Contributor

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.

@coolcat-creations
Copy link
Contributor

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 :-)

@brianteeman
Copy link
Contributor

And this PR just makes that situation worse and not better

@coolcat-creations
Copy link
Contributor

no, its about to solve it

@bembelimen
Copy link
Contributor

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)

@bembelimen bembelimen added the Updates Requested Indicates that this pull request needs an update from the author and should not be tested. label Mar 4, 2024
… 5.1-fields-regex

# Conflicts:
#	administrator/language/en-GB/plg_fields_text.ini
#	plugins/fields/text/params/text.xml
@Hackwar
Copy link
Member Author

Hackwar commented Mar 4, 2024

I removed the controversial validation rules again.

@brianteeman
Copy link
Contributor

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

but no changes to the conceptual approach?

@Hackwar
Copy link
Member Author

Hackwar commented Mar 5, 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.

@coolcat-creations
Copy link
Contributor

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.

@Hackwar
Copy link
Member Author

Hackwar commented Mar 5, 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.

@bembelimen
Copy link
Contributor

bembelimen commented Mar 14, 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.

@brianteeman
Copy link
Contributor

finaly someone gets it!!

@HLeithner HLeithner changed the base branch from 5.1-dev to 5.2-dev April 24, 2024 09:07
@HLeithner
Copy link
Member

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

@HLeithner HLeithner changed the title [5.1] Fields: Add validations to text custom field [5.2] Fields: Add validations to text custom field Apr 24, 2024
@crimle
Copy link

crimle commented Jul 15, 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.

@brianteeman
Copy link
Contributor

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

@crimle
Copy link

crimle commented Jul 16, 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!

@HLeithner HLeithner changed the base branch from 5.2-dev to 5.3-dev September 2, 2024 08:51
@HLeithner
Copy link
Member

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

@HLeithner HLeithner changed the title [5.2] Fields: Add validations to text custom field [5.3] Fields: Add validations to text custom field Sep 2, 2024
@Hackwar Hackwar removed the PR-5.2-dev label Sep 3, 2024
@ghost
Copy link

ghost commented Sep 5, 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.

@crimle
Copy link

crimle commented Sep 5, 2024

I have not tested this item.


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

@HLeithner HLeithner changed the base branch from 5.3-dev to 6.0-dev March 4, 2025 17:21
@HLeithner
Copy link
Member

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

@HLeithner HLeithner changed the title [5.3] Fields: Add validations to text custom field [6.0] Fields: Add validations to text custom field Mar 4, 2025
@rdeutz rdeutz removed the PR-5.3-dev label Mar 5, 2025
@Hackwar Hackwar marked this pull request as draft June 16, 2025 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Language Change This is for Translators PR-6.0-dev RMDQ ReleaseManagerDecisionQueue Updates Requested Indicates that this pull request needs an update from the author and should not be tested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants