RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.36k stars 2.18k forks source link

Cursor moves to start when there is a 0 in the decimal, How to stop this behavior? #2784

Closed iHamzaKhanzada closed 2 months ago

iHamzaKhanzada commented 3 months ago

I first made sure I am using the latest and greatest version of inputmask (without obviously the jquery-inputmask as it has been deprecated), the version is 5.0.9-beta.62. I downloaded this release from the Github, opened the index.html page which has 3 textboxes, date, currency and email. My concern is purely with currency, here is the HTML of the demo I am testing

image

so here are the steps to reproduce:

Working scenario: Type $ 0.51 in the currency textbox, leave the textbox and then click again on the textbox on the right most decimal part (1 in this case), the cursor stays where we have clicked, (Screenshot attached for reference)

image

Now the other case: Type $ 0.50 in the currency textbox, leave the textbox and then click again on the textbox on the right most decimal part (0 in this case), the cursor pushes back to start, this should not happen (I want to disable this behavior of cursor moving) (screenshot attached)

image

Another scenario: Type $0.05 in the currency textbox and leave the textbox and then click again on the textbox pointing the cursor before the 5 decimal part, the cursor moves back to start, unwanted behavior, screenshot attached

image

Techn1c4l commented 3 months ago

I was able to reproduce the same behavior. I think this might be a bug. The reason is you have the option positionCaretOnClick set to the default value of radixFocus. So as I understand, the examples with 0.50 and 0.05 work correctly and the example with 0.51 doesn't.

There is a workaround for this - set positionCaretOnClick to none like this: <input-mask alias="currency" prefix="$ " positionCaretOnClick="none"></input-mask>

iHamzaKhanzada commented 3 months ago

Thanks, using positionCaretOnClick fixed the issue.

RobinHerbots commented 2 months ago

@iHamzaKhanzada , @Techn1c4l ,

Version 5.0.9-beta.68 updated the radixFocus to more desirable behavior.