-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
for Regexp validator set html input tag 'pattern' attribute #759
base: main
Are you sure you want to change the base?
for Regexp validator set html input tag 'pattern' attribute #759
Conversation
…novalidate not set on a form) test that pattern shows up in the input field
4b91b87
to
b86c625
Compare
Thank you for you contribution. Also, can you add a CHANGELOG entry? For the record, the related doc : https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern |
def test_regexp_message(dummy_form, dummy_field, grab_error_message): | ||
""" | ||
Regexp validator should return given message | ||
""" | ||
validator = regexp("^a", message="foo") | ||
dummy_field.data = "f" | ||
assert grab_error_message(validator, dummy_form, dummy_field) == "foo" | ||
|
||
|
||
def test_regexp_pattern_html(dummy_form, dummy_field): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure of the point of this test. I suppose the assertion could go on test_regex_passes
.
... need to check again .. I was not that sure about proper testing here. will take a closer look Thx! |
I was thinking that python and JS regex might have different features: see here or here. In that case, a valid python regex might not be a valid JS regex. There are compatibility layers like https://pypi.org/project/js-regex/ (but this one is unmaintained). As differences mainly concerns advanced regex, i am not sure this is a problem. |
@lefty01 are you interested in finishing the PR or would you like to let someone else take it over? |
IMHO this should be configurable. You might not always want to send the pattern to the client, or you may want to use regex features not supported in the browser. |
well, interested yes of course but right now it's not on top of my list ;) |
FYI: In my experience with HTML
|
for Regexp validator set html input tag 'pattern' attribute (used if novalidate not set on a form)
Similar to the Length validator that sets the html input attributes minlength and maxlength I found it useful to have this for regex patterns as well.
One advantage of using the browser is to get the message translated already (even tough here it is a bit generic, since it only says input needs to match the requested format and does not tell about the format itself)
added some basic test ... not sure if that is accepted this way?