changhuixu / ngx-digit-only

An Angular directive to only allow [0-9] in the input box when typing, pasting or drag/dropping.

Home Page:https://changhuixu.github.io/ngx-digit-only/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Limit input decimal places not working

a0y1a opened this issue · comments

commented

Digit Only input only allows three decimal places not working for me. I don't know what caused it.

See pictures below:

0
1

@a0y1a, I have test it and it works (your pattern is correct)

I think that the problem comes from record.score. If it has 1.1234567, the input will reflect its value, although it's 'invalid'.

Have you fill the input by hand or it's the binded value?

commented

The binded value is zero, then I change and fill the input by hand. According to my understanding, after I typed 1.123, if I go on typing 4, it should be prevented. Do I miss something or should I do something else to implement it ?

Hi @a0y1a, I am not able to reproduce this problem. Please try this example in StackBlitz. I have tried Chrome, Edge, Firefox. All of them works, i.e., the input only allows 1.123.

I am afraid that you are using a different browser, but shouldn't matter, because keyboard event is almost generic across browsers. Another possible reason could be something like an iframe that prevents this directive act on your Angular module.

Anyway, you can start from the StackBlitz example, and work towards your component to see if you can reproduce the error.

commented

@changhuixu Thanks for your feedback. I use Chrome. I tried example in StackBlitz, it works well. Then I copy the example in my project and run it in a new tab, it works not well. No error tips on chrome console. I will try to explore what causes this problem.

close this issue due to lack of reproducibility.