-
Notifications
You must be signed in to change notification settings - Fork 48
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
Comma ? #7
Comments
I ran into this and came up with a hack/workaround. Explanation below and file: jquery.numpad.js.zip I need to accept decimal numbers without a leading 0. The keypad should add the leading zero if it's not there i.e.) Entering ".3" should be acceptable and show "0.3". How it works currently: If a number is pressed after a decimal point (first press "." then press "3") the entire input is cleared. "3" will be shown. The reason is the nmpd.getValue() function in jquery.numpad.js uses the native javascript isNaN() function to determine if the current input is a number or not. isNaN('.') returns true, so if the user enters a '.' the getValue function will return a 0. Both the getValue and setValue functions need to be updated. Typical usage of the number keys is setValue(getValue + some new value). Basically set the value of the display to the current value plus the key that was pressed. So getValue needs to allow returning "." and setValue needs to add a leading 0 if the value is "." Original getValue() function:
New getValue() and setValue() functions:
|
Specifying the decimalSeparator didn't solve the issue but was part of the solution, all you have to do is to add a replace at line #162:
New code:
|
FYI @rswamy I don't think your solution works as of jQuery 3.3.1. Calling The specified value "0." is not a valid number.
The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)? I'm going to see if I can find a solution tomorrow. EDIT: Just kidding. It looks like your solution works fine as long as you leave the There are a couple quirks.
To resolve the second issue I modified the following code from if (target.prop("tagName") == 'INPUT') {
target.val(nmpd.getValue().toString().replace('.', options.decimalSeparator));
} else {
target.html(nmpd.getValue().toString().replace('.', options.decimalSeparator));
} To: var val = nmpd.getValue().toString().replace('.', options.decimalSeparator);
if (val.length > 0 && val[val.length - 1] === ".") { val = val + 0; }
if (target.prop("tagName") == 'INPUT') {
target.val(val);
} else {
target.html(val);
} |
I think this PR fixes some of the issues mentioned here, including being unable to begin an entry with a decimal separator, whichever is for your locale. |
Good work, but comma clears instead of adding decimals
The text was updated successfully, but these errors were encountered: