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

How to prevent overwriting typed numbers in "Date format with mask" example? #81

Open
demark opened this issue Jul 19, 2019 · 7 comments

Comments

@demark
Copy link

demark commented Jul 19, 2019

Currently in "Date format with mask" example ( __-__-____ ) if for instance it has a value
"11-22-333" if I put a caret here: 11-|22-3333 and type "44"
it will overwrite "22" => 11-44-|3333.
Seems like all "Date format" examples have such behavior.
How to prevent this? Eg. block any input until you remove at least one number.

Another bug I noticed with this example:

  1. Type "11-22-3333|"
  2. Move caret to "11-22|-3333" and remove (backspace) two numbers => "11|-33-33__"
  3. Type "44" => "11-44-|33__" (expected result: "11-44-|3333").

Thanks in advance!

@istarkov
Copy link
Contributor

have u tried mask={false} prop?

@demark
Copy link
Author

demark commented Jul 19, 2019

https://codesandbox.io/embed/github/istarkov/rifm/tree/gh-pages/codesandboxes/date-format

mask={false} fixes the bug, but still doesn't prevent overwriting typed values. I can get the expected behavior by removing replace prop and setting maxlength="10" input's attribute, but obviously that's no longer an input with mask "__-__-____".

@istarkov
Copy link
Contributor

still doesn't prevent overwriting typed values

what this means?

Kapture 2019-07-19 at 16 29 23

No overwrite I see, just usual insert with mask={false}

@demark
Copy link
Author

demark commented Jul 19, 2019

Your gif shows I guess the default behavior:
12-34-|1234, type 9999, result => 12-34-9999|.
Desired result: no changes at all once mask is fulfilled, ie. 12-34-|1234 (doesn't change on any input and keeps caret position). ATM, you can achieve this with props mentioned in my previous comment, but with a trade-off of disabling the explicit mask feature (ie. __-__-____).

@istarkov
Copy link
Contributor

How to edit if no changes?

@demark
Copy link
Author

demark commented Jul 19, 2019

block any input until you remove at least one number.

In other words, emulate the same behavior as <input type="text" maxlength="10" />. Once you typed 10 chars, input prevents any changes until you remove some chars.

@antiold
Copy link

antiold commented Oct 23, 2019

The project text-mask has an option Keep character positions, it avoids any replace when the input is full, more user friendly I would argue.
And it gives a nice format that keeps the cursor caret.

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