question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with numeric inputmask

See original GitHub issue

Hi,

I used the following mask for my input (Tested on the latest version).

input.inputmask("decimal", {
    placeholder: "0",
    digits: 2,
    digitsOptional: false,
    radixPoint: ",",
    groupSeparator: ".",
    autoGroup: true,
    allowPlus: false,
    allowMinus: false,
    clearMaskOnLostFocus: false,
    removeMaskOnSubmit: true,
    onUnMask: function(maskedValue, unmaskedValue) {
        var x = unmaskedValue.split(',');
        if (x.length != 2)
            return "0.00";
        return x[0].replace(/\./g, '') + '.' + x[1];
    }
});

First I noted that with default options where {radixPoint: β€œ.”, groupSeparator: β€œ,”, autoGroup: true}, the mask function does not work correctly. For example, if I set β€œ10000” or β€œ10000.00” to my input which comes from my database, the masked value is β€œ100.00”.

Then when I used {radixPoint: β€œ,”, groupSeparator: β€œ.”, autoGroup: true} options, the mask function also does not work and the unmask function does not unmask the value, i.e., the unmask function returns the same value. For example, if my input has value β€œ1.000,00”, the unmask function returns β€œ1.000,00”. But with the default options, the unmask function returns the value correctly, i.e., taking off the groupSeparator(β€œ,”) from the value. My solution was to define what to return using onUnMask.

I found another problem when I use {autoGroup: true, clearMaskOnLostFocus: false} to insert groupSeparator. I do not know how to explain well that problem, so I will try to be clear enough. With this options, the input first show the value β€œ0.00”. When I focus the input the cursor goes to before radixPoint and I type β€œ123456”, the input value will be β€œ123,456.00”. But if I focus again and start erasing the digits with backspace until input value show β€œ,00”, and then focus out the input value is updated to show β€œ000.00”. That happens with {autoGroup: true}, but not with {autoGroup: false}.

I suggest to improve the behavior described when using {autoGroup: true, clearMaskOnLostFocus: false}. But I think that making mask and unmask function work properly is a good idea. I mean that unmask function could return the value with default format, i.e, database decimal format (no groupSeparator and radixPoint:β€œ.”).

I think that your inputmask is great because offer many options like removeMaskOnSubmit, where usually the values are unmasked or converted on the server side, and other options that I have not explored yet.

Thanks.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
FilipeZhoucommented, Jan 12, 2015

@RobinHerbots

Thank you very much for the fixes. Just a suggestion: I have seen in your code that when you mask a value, according to inputmask, you apply the mask replacing the radixPoint (β€˜.’) to the one in inputmask. But when I get the unsmakedvalue, you just take off the groupSeparator from the value. What do you think in replacing back radixPoint to β€˜.’ too? Now I set onUnMask function to my inputmask to do this part:

input.inputmask("decimal", {
    placeholder: "0",
    digits: 2,
    digitsOptional: false,
    radixPoint: ",",
    groupSeparator: ".",
    autoGroup: true,
    allowPlus: false,
    allowMinus: false,
    clearMaskOnLostFocus: false,
    removeMaskOnSubmit: true,
    autoUnmask: true,
    onUnMask: function(maskedValue, unmaskedValue) {
        var x = maskedValue.split(',');
        return x[0].replace(/\./g, '') + '.' + x[1];
    }
});
1reaction
manishkraicommented, Jan 6, 2015

Hi, I am facing same issue -

$(element).inputmask(β€˜decimal’, { radixPoint: β€œ.”, digits: 2, integerDigits: 13, allowMinus: true, autoGroup: true, groupSeparator: β€œ,”, groupSize: 3, skipRadixDance: true });

When I insert a digit (for example, β€œ1”) I get β€œ100”.

Fo more than a digit it’s working fine - like 10 got converted to 10.00, 100 to 100.00 and 1000 to 1,000.00,

Could you please help me to fix this issue.

Regards, Manish

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input mask for numeric and decimal - javascript - Stack Overflow
Ehm... if the database field is numeric(6,2) then the number of decimals can't be "2 or 3 according to choice of the user"....
Read more >
[Input Mask React] Numeric input mask is working, but the ...
Hello, When I use the "MaskNumber" in our application the input mask works on the input field, but the input value is not...
Read more >
Control data entry formats with input masks - Microsoft Support
You can use input masks with fields that are set to the Text, Number (except ReplicationID), Currency, and Date/Time data types. Note: If...
Read more >
Easy JavaScript/jQuery Input Mask Plugin - inputmask
jQuery Input Mask is a lightweight and easy-to-use jQuery plugin that ... Fixed: UX problem with email mask; Fixed: Force numeric to emptyΒ ......
Read more >
[Solved] Mask TextBox value not working for Numeric Keypad ...
[Solved] Mask TextBox value not working for Numeric Keypad in jQuery ... < script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.3.4/Β ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found