Skip to content
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

[4.0] component config form not saving when validation fails on empty field #34102

Closed
Ruud68 opened this issue May 22, 2021 · 10 comments
Closed

Comments

@Ruud68
Copy link
Contributor

Ruud68 commented May 22, 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

@brianteeman
Copy link
Contributor

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

@Ruud68
Copy link
Contributor Author

Ruud68 commented May 22, 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

@brianteeman
Copy link
Contributor

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

@brianteeman
Copy link
Contributor

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

@Ruud68
Copy link
Contributor Author

Ruud68 commented May 22, 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 :)

@brianteeman
Copy link
Contributor

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

@Ruud68
Copy link
Contributor Author

Ruud68 commented May 22, 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

@PhilETaylor

This comment was marked as abuse.

@Ruud68
Copy link
Contributor Author

Ruud68 commented May 23, 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

@joomdonation
Copy link
Contributor

Closing as there is PR #34124.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants