RobinHerbots/Inputmask

Unmasked value stopped working in version `5.0.9`

AFatNiBBa opened this issue · 1 comments

Description

There's a bug when getting the unmasked value if the "shape" of the inputFormat is different from the outputFormat's one.
In this CodePen I made a variable called workingVersion that chooses which inputFormat to use.

If you set it to true it will use "dd/mm/yyyy", and the value you insert will be unmasked correctly, while if you set it to false it will use ' dd mm yyyy ', which doesn't work.

If, on the HTML panel, you change the version of the script that imports the library from 5.0.9 to 5.0.8, everything works fine

Info

OS Windows 11
Browser Tried on both Edge (Chromium) and Chrome
Inputmask version 5.0.9

As a temporary workaround, you can manually produce the desired output format using onUnMask event handler like this:

$("#field").inputmask({
  alias: "datetime",
  inputFormat: workingVersion ? "dd/mm/yyyy" : ' dd  mm  yyyy ',
  placeholder: "_",
  onUnMask: (maskedValue, unMaskedValue) => {
    const parts = maskedValue.trim().split(/\s+/);
    return parts[2] + '-' + parts[1] + '-' + parts[0];
  },
  oncomplete() {
    $("#out").text($(this).inputmask('unmaskedvalue'));
  }
});