HTML5 input patterns are a way of adding simple validation rules using regexp directly in the form field.
HTML5 input patterns just like the required attribute are checked immediately and not on submit so they provide instant feedback. This not only reduces calls to the server but also improves the usability and accessibility of the form.
Input patterns are supported by the Joomla text field but they should also be supported by search, tel, url, email, and password fields.
J4 has partial support for custom validation messages but is not using the specification for the value in the xml
Finally although Joomla supports this in the text fields so it will work in a field defined in an xml file there is no UI to be able to use this in a custom field.
https://github.com/joomla/joomla-cms/blob/staging/layouts/joomla/form/field/text.php#L75
https://github.com/joomla/joomla-cms/blob/4.0-dev/layouts/joomla/form/field/text.php#L72
See media-action-crop plugin in J4
A regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url, email, or password, otherwise it is ignored. The regular expression language is the same as JavaScript RegExp algorithm, with the 'u'parameter that makes it treat the pattern as a sequence of unicode code points. The pattern is not surrounded by forward slashes.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-pattern
Supported by all browsers see https://caniuse.com/#feat=input-pattern
Add [a-z]{1,15} as the value of the pattern attribute in our username input:
<input
type="text"
name="username"
placeholder="Username"
pattern="[a-z]{1,15}”>
Now, since it only accepts lowercase letters, submitting any other value will throw an error message immediately
We can customise the message to be more helpful by specifying a title attribute within our input element:
<input
type="text"
name="username"
placeholder="Username"
pattern="[a-z]{1,15}"
title="Username should only contain lowercase letters. e.g. john">
Now the title is included along with the default message:
Labels |
Added:
?
|
Category | ⇒ | Feature Request Fields |
I am not talking about dropping the more advanced validation scripts.
I am talking about using the already partially supported pattern functionality
+1
Wouldn't addings a pattern to tel
inputs be an absolute nightmare with multilingual sites?
That would be upto the site owner :) but we already have a validation rule for Tel formats that someone can use and it's completely useless :)
Status | New | ⇒ | Discussion |
@brianteeman if I understand correctly your request here there are 2 parts:
Basically yes
The js team can fix the js part but the forms xmls is a mountain of work and we’re way behind our schedule
If accepted the xml is something i can do
the js can probably be removed IF/WHEN this is implemented
NOTE we dont necessarily have to implement it in the core xml immediately that can wait for another time.
But we should be able to support it in com_fields and custom development
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-03-25 18:03:53 |
Closed_By | ⇒ | brianteeman |
Closed due to lack of interest
@brianteeman about the validation message customisation: I've already included some code in the validation.js for that:
joomla-cms/media/system/js/fields/validate.js
Lines 80 to 99 in bf3039a
Just to mention that the proposal to drop the old validation script for a new fully HTML5 compliant was rejected (I think at the London sprint) mainly for B/C reasons