-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
JFormValidator - Optional field with pattern attribute marked invalid #19751
Comments
make sense if ($el.val().length) {
isValid = new RegExp('^'+$el.attr('pattern')+'$').test($el.val());
handleResponse(isValid, $el);
return isValid;
}
if ($el.attr('required') || $el.hasClass('required')) {
handleResponse(false, $el);
return false;
}
handleResponse(true, $el);
return true; |
J4 has the code you’re looking for, someone needs to backport it here |
Looks like J4 will have the same issue: https://github.com/joomla/joomla-cms/blob/4.0-dev/media/system/js/fields/validate.js#L165-L172. It defaults to false in the else statement, can this default to true instead? |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/19751 |
closed as having Pull Request #19771 |
Steps to reproduce the issue
Add the following field to any module manifest
Click on the test field and then select another without filling anything in. This will happen on any form which uses JFormValidator / JHtml::_('behavior.formvalidator');
Expected result
The field to not be marked as invalid
Actual result
Gets highlighted red and marked as invalid.
System information (as much as possible)
Joomla 3.8.5
Additional comments
Optional fields should only validate a pattern when a value is present. validate.js already checks for value.length but defaults to false if length is 0: https://github.com/joomla/joomla-cms/blob/staging/media/system/js/validate-uncompressed.js#L89-L96. Removing the else statement solves this but i'm not sure if this had been added intentionally.
This same issue is also present with J4.
The text was updated successfully, but these errors were encountered: