?
avatar Ruud68
Ruud68
22 May 2021

Steps to reproduce the issue

In order to be able to reproduce this follow the below instruction (otherwise I had to create a component that needed to be installed).

  1. in ./administrator/components/com_content/config.xml add the following field:

<field name="email" type="text" pattern=".*@.*\..*" label="TESTFIELD" description="" />

  1. in the back-end of the j4 site goto articles options
  2. leave the TESTFIELD empty
  3. click [save] button

Expected result

Configuration should save (TESTFIELD is empty and NOT required)

Actual result

save action throws error:

The form cannot be submitted as it's missing required data.
Please correct the marked fields and try again.
screen shot 2021-05-22 at 14 10 06

System information (as much as possible)

J4 dev 8 (nightly)
PHP 8.05
mysql 8.0.25

Additional comments

saving with this field and (empty) value works correct in J3

avatar Ruud68 Ruud68 - open - 22 May 2021
avatar joomla-cms-bot joomla-cms-bot - labeled - 22 May 2021
avatar Ruud68 Ruud68 - change - 22 May 2021
The description was changed
avatar Ruud68 Ruud68 - edited - 22 May 2021
avatar brianteeman
brianteeman - comment - 22 May 2021

Could you check that the problem is not the pattern. ie its trying to check if the empty value matches the regex in the pattern

avatar Ruud68
Ruud68 - comment - 22 May 2021

the pattern works in J3 (saving with empty value gives no error) and gives this behavior in J4, so the issue is not in the pattern, but in the handling of the pattern

avatar brianteeman
brianteeman - comment - 22 May 2021

I am surprised it works in j3 because the pattern is a validation rule and an empty field doesnt match the pattern

avatar brianteeman
brianteeman - comment - 22 May 2021

anyway if you use type=email then the browser does it for you

avatar Ruud68
Ruud68 - comment - 22 May 2021

anyway if you use type=email then the browser does it for you

sure, but this is an example of what seems like a B/C. There are patterns developers use that are not in the type list :)

avatar brianteeman
brianteeman - comment - 22 May 2021

unless I am very much mistaken html5 pattern validation is done by the browser not joomla

avatar Ruud68
Ruud68 - comment - 22 May 2021

You are mistaken (sorry), issue is in validate.js
it validates against the pattern only when length of the field is not 0
if length is zero it checks if it is required (which it isn't)
then it should return true, but it return false (where the validation in J3 correctly returns a true)

because it returns a false, the error is thrown.

So somebody with knowledge of JS should have a look at line 685 of file ./media/system/js/fields/validate.js

avatar Ruud68 Ruud68 - change - 22 May 2021
The description was changed
avatar Ruud68 Ruud68 - edited - 22 May 2021
avatar PhilETaylor
PhilETaylor - comment - 23 May 2021

pattern=".*@.*\..*"

Is this only a test or are you using something with this regex in real life? It would not be valid, as phil@myInternalServer is a valid email address and would fail that pattern.

avatar Ruud68
Ruud68 - comment - 23 May 2021

pattern=".*@.*\..*"

Is this only a test or are you using something with this regex in real life? It would not be valid, as phil@myInternalServer is a valid email address and would fail that pattern.

this is just a simple test to show the B/C issue with J4 form field validation :) #noworries

avatar joomdonation joomdonation - change - 23 May 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-05-23 14:01:57
Closed_By joomdonation
avatar joomdonation joomdonation - close - 23 May 2021
avatar joomdonation
joomdonation - comment - 23 May 2021

Closing as there is PR #34124.

Add a Comment

Login with GitHub to post a comment