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

prop.pattern produces invalid html #605

Open
Samuel-Dufour opened this issue May 20, 2024 · 4 comments
Open

prop.pattern produces invalid html #605

Samuel-Dufour opened this issue May 20, 2024 · 4 comments

Comments

@Samuel-Dufour
Copy link
Contributor

The prop.pattern function available on input to provide a validation pattern takes a regular expression parameter and generates a js regex instead of the pattern only.

For example
prop.pattern (System.Text.RegularExpressions.Regex "\d{2}:\d{2}:\d{2}") produces pattern="/\d{2}:\d{2}:\d{2}/gu"

What should be produced is pattern="\d{2}:\d{2}:\d{2}".

A workaround is to use Interop.mkAttr "pattern" "\d{2}:\d{2}:\d{2}" so it could replace the current implementation but it means the pattern validity is checked later.

@Zaid-Ajaj
Copy link
Owner

Can we process the given regular expression so that it does give prop.pattern a valid pattern instead?

@MangelMaxime
Copy link
Contributor

Looking at example online it seems like prop.pattern expect a string and not a RegExp instance, so I think we should just change it to string.

<label for="username">Username: (3-16 characters)</label>
<input id="username" name="username" type="text" value="Sasha" pattern="\w{3,16}" required />

<label for="pin">PIN: (4 digits)</label>
<input id="pin" name="pin" type="password" pattern="\d{4,4}" required />

@Zaid-Ajaj
Copy link
Owner

I've added an overload that accepts a string as for the regex, will try to see if we can get that to work

@MangelMaxime
Copy link
Contributor

will try to see if we can get that to work

IHNO this never worked. Both React and MDN hints to the fact that pattern is an HTML property accepting a string.

pattern: A string. Specifies the pattern that the value must match.

The wording on MDN is confusing:

The pattern attribute specifies a regular expression the form control's value should match.

But later, it does mention it as

The pattern's regular expression is compiled with the 'v' flag.

Meaning that this is indeed the string representation of the pattern that can then be used to as an argument to RegExp.

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

No branches or pull requests

3 participants