Skip to content

Conversation

@dgrammatiko
Copy link
Contributor

@dgrammatiko dgrammatiko commented Dec 5, 2016

Pull Request for Issue #12857 .

Summary of Changes

HTML5 NATIVE validation is done through pattern="something"
The validate.js is adjusted so if pattern tag exists will take precedence else we fall back to the rules

Testing Instructions

Add pattern="[a-zA-Z]+" after https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_content/models/forms/article.xml#L13
Create a new article and try to submit without a title or with title as 87587676 (or anything apart english alphabet letters)

screen shot 2016-12-05 at 16 35 31

@Fedik @ggppdk @mbabker


This change is Reviewable

Copy link
Contributor

@ralain ralain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure it's not going to work with a regex literal. You might try something like this, instead:

isValid = new RegExp($el.attr('pattern')).test($el.val());

@Fedik
Copy link
Member

Fedik commented Dec 10, 2016

works good 👍
but I think better to change as @ralain sugested

@ralain
Copy link
Contributor

ralain commented Dec 10, 2016

Looked into this further and as I suspected you can't use a variable in a JavaScript regex literal. The variable itself (not its value) becomes the pattern.

Also, html5 pattern and JS regex are not fully compatible, but it's fixed easily by adding start and end of string, like so:

isValid = new RegExp('^'+$el.attr('pattern')+'$').test($el.val());

@dgrammatiko
Copy link
Contributor Author

@Fedik @ralain I've pushed the suggested code

@ralain
Copy link
Contributor

ralain commented Dec 15, 2016

I have tested this item ✅ successfully on 73c97f8

HTML5 pattern and JS validation match up perfectly, now. Thanks for this.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13094.

@Fedik
Copy link
Member

Fedik commented Dec 18, 2016

I have tested this item ✅ successfully on 73c97f8


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13094.

@zero-24 zero-24 added this to the Joomla 3.7.0 milestone Dec 18, 2016
@zero-24 zero-24 added the RTC This Pull Request is Ready To Commit label Dec 18, 2016
@rdeutz rdeutz merged commit 52d8bc0 into joomla:staging Dec 18, 2016
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Dec 18, 2016
@dgrammatiko dgrammatiko deleted the _____html5_validation branch December 18, 2016 13:27
@gptforjoomla
Copy link
Contributor

Hi, this pull has a problem with unrequired inputs. test: a field that is not required but has pattern to be a number or other . when user not enter value for this input and submit, validation say that field is not correct

@ghost
Copy link

ghost commented Nov 17, 2017

@minijoomla is this similar to #18591?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants