Hi, i’m having problems with numericupdown control in “es-ES” culture, for example:
if enter (with numeric keyboard) :
0.02 –> Press tab key –> 0,0200
0.0223 –> Tab –> 0,0223
0.2 –> Tab –> 0,2000
0.025 –> Tab –> 25,0000
1.235 –> Tab –> 1235,0000
only when number entered have three decimals.
when use: “culture”: “en-US” in Default.json all works ok.
Thanks,
Mariano
Hi Mariano,
This is a common problem with localization mismatch between the client OS and the formatting/parsing locale used by the app. It’s not a Wisej issue. It happens in .NET, Java, javascript, etc. Many years ago one app we migrated to .NET (WinForms) for a cargo company generated a manifest loading the boat 1000 times more than it could take, on paper. 🙂
The problem is your OS/keyboard is set to en-US and converts the dot from the keypad to a decimal point but the app expects a decimal comma. “0.025” converts to 25. You can verify this by parsing the string “0.025” using es-ES in .NET as well. Somehow the javascript parser is able to understand that 0.0223 is 0,0223. But if you try the same in .NET you get 223. They are both wrong and correct at the same time.
If you enable the language bar in Windows you can switch the kayboard layout and have the decimal comma instead of the decimal point (or thousand separator).
HTH
Best,
Luca
Hi Luca, sorry, forget to mention that i replaced numeric control with textbox control, anyway user can enter multiple commas, so validation before save data is needed.
I think is better replace ‘.’ for ‘,’ in the event but I don´t know how to replace a keyCode in keyDown event.
Thanks,
Mariano
Hi Mariano,
The NumericUpDown control in Wisej already only allows numbers, delete, arrows, dots and commas. The javascript code you posted would only append the “,” when pressing the dot, but it doesn’t work when the caret is in the middle of the number.
Best,
Luca
Hi, in client side possible solution is permit only numbers, back, delete, tab, arrows and convert dot to comma, not use keypress event because keycode for ‘dot’ and ‘delete’ keys are same (46)
// attach the keydown event. // this = the widget that corresponds to the // control on the server. this.addListener("keydown", function(e) { // get the identifier for the presses key. // see https://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-KeyboardEvent-keyIdentifier var code = e.getKeyCode(); if (((code>34 && code<41) || code==8 || code==9) || code==188 || code==110 || code==190 || (code>=44 && code<=57) || (code>=96 && code<=105)) { if (code==110 || code==190) { this.setValue(this.getValue() + ","); // stop the event from propagating. e.stop(); } } else { // stop the event from propagating. e.stop(); } });
Regards,
Mariano