Closed dsschnau closed 8 years ago
Argh, you're totally right. On paste, preventInvalidInput
doesn't do anything right. I'm a little worried about changing the entire logic of that method (especially since allowedPattern
isn't really a regex, is more like a pattern, so if you validate it as a regex it's probably going to fail).
I'm also not 100% sure what the behaviour should be when you paste something incorrect -- should nothing happen? In that case, we could maybe add an event listener for the paste
event, checking each of the characters of the pasted text against the method (kind of like if they were typed one by one), and if any are invalid, don't commit the text.
What do you think? This would leave the status quo as it is, and fix the broken paste behaviour.
I've renamed the issue. I don't think the problem is with the code (since again, allowedPattern
is not really a regex, so it won't match), but with the paste event
Firstly thanks for the detailed answer, very much appreciated.
I agree there isn't much problem with the code but it is important to clarify what allowedPattern
really means in the documentation (with your blessing I'll gladly make a PR for it).
To answer your question about what should happen when pasting, I have two thoughts.
The first, more literal interpretation of the intent of allowedPattern
, is that only the characters pasted that match the pattern are committed to the iron-input
.
However, that might cause some very misleading things downstream. For example, a user pastes a model number (say "M49X
") for some widget into an iron-input
whose allowedPattern
is [a-zA-Z]
and is confused as to why only the letters are being pasted MX
"What happened to the 49
?".
The second, and what I think makes the most sense unless there's a good reason I'm not thinking of, leaving it the way it is (and clearly documenting it) would probably be the best idea.
Documenting it then would be great. I was thinking that if you try to paste M49X
you would actually get nothing (so none of the characters would be committed), but that's still a bit of a baffling interaction.
I think adding a note about how this prevents the user typing invalid input, but won't actually affect pasting would be amazing! Make sure to CC me on the PR so I can review it :)
Thanks!
The description of
allowedPattern
is as follows:I had assumed that the pattern combined with
preventInvalidInput
would check the value of the entirety ofvalue
. After digging into the code I discovered that when a user types a new character into aniron-input
with these properties set up,paper-input
validates not against the entirety of the newvalue
but rather only the single character checked.Along with this, when content is pasted into an
iron-input
, I expected that the entire string would be validated against, but instead I found that each individual character has the regex tested against it.I understand that changing it would break a lot of things for other users but I personally don't think this is the best approach.
So I propose two things:
iron-input
instead of individual characters