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

Proper usage for AsYouType formatter #75

Closed
slavafomin opened this issue May 10, 2017 · 3 comments
Closed

Proper usage for AsYouType formatter #75

slavafomin opened this issue May 10, 2017 · 3 comments

Comments

@slavafomin
Copy link

Hello!

Thank you for this great module!

However, I'm trying to use AsYouType formatter in order to format user input in my Angular 2 application.

I'm creating an instance of asYouType with the input component and I can feed new numbers to it by listening to the keyup event of the input element: input.value = formatter.input(event.key); and it works great. But, when I press backspace it continues to render previous value, because it doesn't know about removed character. So, how do I tell it to actually remove one character?

The only workaround I've found so far is to create new instance of the formatter on each keyup event and to feed entire input value to it. It works flawlessly, but it's terrible from the design perspective and probably performance (creating a new instance of the object and calling a function on it is probably a serious overkill).

How do I use it correctly and at the same time achieve better design and performance?

Thanks!

@catamphetamine
Copy link
Owner

You guessed right – just create a new instance every time.
I didn't measure the performance penalty: perhaps it could be .reset() somehow, but I didn't check that.

@slavafomin
Copy link
Author

This looks like a serious design flaw, why do you need an input() function capable of accepting numbers one by one, when you actually passing entire string to it all the time?

@catamphetamine
Copy link
Owner

This looks like a serious design flaw

No it doesn't

you actually passing entire string to it all the time

No, someone may pass digits one-by-one and there is no restriction to passing the "entire string to it all the time"

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

2 participants