-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
<textarea> should support the [pattern] attribute like the <input> element #9102
Comments
Can you give concrete examples of where this would be useful? |
@zcorpan there is simply no reason for it to be not implemented to be honest. I don't remember my original case - this issue is 6 years old. I guess that I really didn't want to have any numbers or special characters in the textarea, but for what bizzare reason I have no idea. Maybe I was using textarea just like an input, but used some of it's special behaviors to achieve some end-result. Probably I was hacking something. |
We generally don't add features without knowing that they're useful for something. See https://whatwg.org/faq#adding-new-features in particular step 2. |
Anywhere you want to allow the user to input a list of items, one item per line, where each item can be matched against a specified regex. For example, assuming Other common use cases would be newline-delimited lists of emails, usernames, file hashes, IP addresses, etc. |
The use case which triggered me to look into this is a An When I insert content into a form as a user, I expect it to tell me if I am doing something unsupported and guide me on how to correct my content, the type of form element does not matter. Currently, everyone has to work around this by manually implementing client-side validation in Javascript in an attempt to imitate the existing validation of |
Thanks. Can you link to any live sites that are working around the lack of this feature with JS?
Maybe |
@zcorpan this is extremely limiting, plus probably much harder to implement right. Input was always single line. The moment you add |
@zcorpan Why is a pattern useful in an input element? Why shouldnt it be useful for the same reasons in a textarea element? |
I'm not saying it's not useful. The party proposing a change bears the burden of presenting convincing arguments for the change, and I'm trying to guide how you can do so. If there's concrete examples where this feature would be useful it's possible to assess cost/benefit and how well different proposals address the use cases. As for |
Use case: Example: |
I think most web developers' mental model of
I have a live site using a JS workaround for this (for a newline-delimited use case similar to the one I outlined), but it's a platform used internally at my company, not a public-facing site. There's also this StackOverflow question from 10 years ago with various answers containing JS workarounds. Presumably some others of those are in live use. |
Usages of We can go through some of these (currently 92 files) to learn how it's used. For example, should the regexp match per line or on the whole value? Which regexp flags? |
Might also be instructive to check for bare https://github.com/search?type=code&auto_enroll=true&q=%2F%3Ctextarea%5B%5E%3E%5D%2B+pattern%3D%2F Most of those look to be regexes used analogously with |
@lionel-rowe thanks, good point! There's also the possibility that some are using the attribute in a bogus way and actually expect no validation. In such cases, and possibly in the polyfill cases, starting to support the attribute is a risk to break web compat. |
As I am not a native english speaker, just to be clear I understood what you are saying: |
Yes. If browsers add support for it and that causes web sites to stop working, then it's not implementable. This is something that has happened several times in the past (e.g. It might be fine, but it needs some analysis to understand the impact. |
Thanks for sharing, helped me a lot to understand. |
We have textareas where the server-side will look for common spam patterns, such as URLs, and drop those messages. Spammers won't care about pattern (or any client-side validation for that matter), but we want to show a warning to real users. The Right now we've built our own polyfill that pulls the regex from the attribute, runs it in client-side (custom) JS to show a warning. So it works for us, but native support had been better. |
Preventing submitting whitespace only strings. |
The input
[pattern]
attribute should be usable with<textarea>
as well, equivalent to:https://html.spec.whatwg.org/multipage/input.html#the-pattern-attribute
<textarea>
supports[minlength]
and[maxlength]
but sometimes that is not enough.For example: sometimes one may want to limit available characters in
<textarea>
to letters-only.Original issue from w3c by @soanvig: w3c/html#1028
The text was updated successfully, but these errors were encountered: