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

Inputmask cursor stuck if is placed before "." or "-" #2840

Open
kingleonide opened this issue Mar 16, 2025 · 0 comments
Open

Inputmask cursor stuck if is placed before "." or "-" #2840

kingleonide opened this issue Mar 16, 2025 · 0 comments

Comments

@kingleonide
Copy link

kingleonide commented Mar 16, 2025

Issue description

When setting a value programmatically in an input field with an applied Inputmask, an issue occurs: if the cursor is placed before a "." or "-", the mask stops functioning correctly, and further input becomes impossible.

Steps to reproduce

  1. Include jQuery and the Inputmask library (version 5.0.2 or later).
  2. Add an input field to the page and apply the following mask: 99.99.99 - 99.99.99.
  3. Programmatically set the value to 16.03.25 - 17.03.25 (random).
  4. Try placing the cursor before a "." or "-".

Expected Behavior

The cursor should be able to move freely within the input field without blocking data entry.

Actual behavior

When the cursor is placed before "." or "-", the mask freezes, and input becomes impossible.

Tested versions

  • Version 4.0.9: Works correctly.
  • Versions 5.0.0 - 5.0.1: The issue occurs only for "-".
  • Version 5.0.2 and later: The issue occurs for both "." and "-".

Example code

<input type="text" data-date-target-pure class="history-filter__input">
<input type="text" data-date-target-jq class="history-filter__input">

<script>
let mask = Inputmask({
  mask: "99.99.99 - 99.99.99",
  placeholder: "dd.mm.yy - dd.mm.yy",
  insertMode: false,
  shiftPositions: false,
}).mask(document.querySelector('[data-date-target-pure]'));

mask.setValue('16.03.25 - 17.03.25');

$(function(){
  $('[data-date-target-jq]').inputmask({
    mask: "99.99.99 - 99.99.99",
    placeholder: "dd.mm.yy - dd.mm.yy",
    insertMode: false,
    shiftPositions: false,
  });
  $('[data-date-target-jq]').val('16.03.25 - 17.03.25');
});
</script>

Live example

JSFiddle

This fiddle contains all tested versions from 4.0.9 to 5.0.10-beta.14 (just uncomment the desired version).
I suspect the issue might be related to the seekNext method used in keypressEvent, but understanding and fixing it is too complex for me.

Affected browsers

The issue occurs in all modern browsers, including Chrome and Firefox.

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

1 participant