IDEMPIERE-4783 Changing the way number field with calculator are handled (#678)
* Fix not filling the box when the initial value is zero * Fix removing the leading zeroes to avoid octal calculations
This commit is contained in:
parent
3211c449cb
commit
759473f6ed
|
@ -48,7 +48,7 @@ Copyright (C) 2007 Ashley G Ramdass (ADempiere WebUI).
|
|||
<javascript-module name="jawwa.atmosphere" version="202102091500"/>
|
||||
<javascript-module name="adempiere.local.storage" version="202011151100"/>
|
||||
<javascript-moudle name="html2canvas" version="1.0.0.rc7"/>
|
||||
<javascript-module name="org.idempiere.commons" version="202012030330"/>
|
||||
<javascript-module name="org.idempiere.commons" version="202105072207"/>
|
||||
<javascript-module name="jquery.maskedinput" version="1.4.1" />
|
||||
<javascript-module name="photobooth" version="0.7-rsd3" />
|
||||
<javascript-module name="chosenbox" version="202012041500"/>
|
||||
|
|
|
@ -137,6 +137,8 @@ public class NumberBox extends Div
|
|||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (btn.getPopup() != null) {
|
||||
// Fill the calculator with the actual value of the field
|
||||
// TODO: this could be made a user preference
|
||||
String curValue = "";
|
||||
if (decimalBox.getValue() != null) {
|
||||
curValue = decimalBox.getValue().toString();
|
||||
|
@ -146,6 +148,9 @@ public class NumberBox extends Div
|
|||
String separator = Character.toString(separatorChar);
|
||||
curValue = curValue.replace(".", separator);
|
||||
}
|
||||
if ("0".equals(curValue)) {
|
||||
curValue = "";
|
||||
}
|
||||
}
|
||||
String txtCalcId = txtCalc.getId();
|
||||
Clients.evalJavaScript("calc.append('" + txtCalcId + "', '" + curValue + "')");
|
||||
|
|
|
@ -73,10 +73,14 @@ function Calc()
|
|||
var re = new RegExp("[" + separator + "]", "g");
|
||||
value = value.replace(re,'.');
|
||||
}
|
||||
var reclean = new RegExp("[^1234567890+-/*%() ]", "g"); // sanitize
|
||||
value = value.replace(reclean,'');
|
||||
var reperc = new RegExp("[%]", "g"); // percentage
|
||||
value = value.replace(reperc,'/100 ');
|
||||
value = value
|
||||
.replace(/[^1234567890+-/*%() ]/g, '') // sanitize
|
||||
.replace(/[%]/g, '/100 ') // percentage
|
||||
// now replace leading zeroes
|
||||
.replace(/\b0+\b/g, 'z') // replace bare zeros with sentinel
|
||||
.replace(/[1-9\.]0+/g, m => m.replace(/0/g, 'z')) // save these too
|
||||
.replace(/0/g, '') // throw away the rest of the zeros
|
||||
.replace(/z/g, '0'); // turn sentinels back to zeros
|
||||
newValue = value;
|
||||
var result = "" + eval(value);
|
||||
if (separator != '.')
|
||||
|
|
Loading…
Reference in New Issue