?
avatar aaron-harding
aaron-harding
21 Feb 2018

Steps to reproduce the issue

Add the following field to any module manifest

<field
	name="test"
	type="text"
	description="testing field validation"
	filter="string"
	label="Test"
	pattern="[A-Za-z\s0-9]+" />

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.

avatar aaron-harding aaron-harding - open - 21 Feb 2018
avatar joomla-cms-bot joomla-cms-bot - change - 21 Feb 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 21 Feb 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 21 Feb 2018
Category Fields
avatar alikon
alikon - comment - 21 Feb 2018

make sense
something like this snippet for https://github.com/joomla/joomla-cms/blob/staging/media/system/js/validate-uncompressed.js#L89-L96

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;
avatar dgt41
dgt41 - comment - 21 Feb 2018

J4 has the code you’re looking for, someone needs to backport it here

avatar franz-wohlkoenig franz-wohlkoenig - change - 22 Feb 2018
Status New Discussion
avatar aaron-harding
aaron-harding - comment - 22 Feb 2018

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?

avatar joomla-cms-bot joomla-cms-bot - change - 24 Feb 2018
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 24 Feb 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 24 Feb 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-02-24 10:37:42
Closed_By franz-wohlkoenig
avatar joomla-cms-bot
joomla-cms-bot - comment - 24 Feb 2018
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 24 Feb 2018

closed as having Pull Request #19771

Add a Comment

Login with GitHub to post a comment