Skip to content

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

@kingleonide

Description

@kingleonide

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions