Problems with numeric inputmask
See original GitHub issueHi,
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:
- Created 9 years ago
- Reactions:2
- Comments:14 (5 by maintainers)
Top GitHub Comments
@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:
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