diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/NumberBox.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/NumberBox.java index 7a97acc7c7..3690fe3b98 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/NumberBox.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/NumberBox.java @@ -90,7 +90,40 @@ public class NumberBox extends Div ZKUpdateUtil.setHflex(decimalBox, "0"); decimalBox.setSclass("editor-input"); decimalBox.setId(decimalBox.getUuid()); - + + char separatorChar = DisplayType.getNumberFormat(DisplayType.Number, null).getDecimalFormatSymbols().getDecimalSeparator(); + String separator = Character.toString(separatorChar); + boolean processDotKeypad = MSysConfig.getBooleanValue(MSysConfig.ZK_DECIMALBOX_PROCESS_DOTKEYPAD, true, Env.getAD_Client_ID(Env.getCtx())); + if (processDotKeypad && ! ".".equals(separator)) { + /* this code works for the decimalbox - the calculator is managed in calc.js */ + StringBuffer funct = new StringBuffer(); + funct.append("function(evt)"); + funct.append("{"); + // ignore dot, comma and decimal separator and process them on key down + funct.append(" if (!this._shallIgnore(evt, '0123456789-%'))"); + funct.append(" {"); + funct.append(" this.$doKeyPress_(evt);"); + funct.append(" }"); + funct.append("}"); + decimalBox.setWidgetOverride("doKeyPress_", funct.toString()); + funct = new StringBuffer(); + // debug // funct.append("console.log('keyCode='+event.keyCode);"); + funct.append("if (window.event)"); + funct.append(" key = event.keyCode;"); + funct.append("else"); + funct.append(" key = event.which;"); + funct.append("if (key == 108 || key == 110 || key == 188 || key == 190 || key == 194) {"); + funct.append(" var id = '$'.concat('").append(decimalBox.getId()).append("');"); + funct.append(" var calcText = jq(id)[0];"); + funct.append(" var position = calcText.selectionStart;"); + funct.append(" var newValue = calcText.value.substring(0, position) + '").append(separator).append("' + calcText.value.substring(position);"); + funct.append(" calcText.value = newValue;"); + funct.append(" calcText.setSelectionRange(position+1, position+1);"); + funct.append(" event.stop;"); + funct.append("};"); + decimalBox.setWidgetListener("onKeyDown", funct.toString()); + } + appendChild(decimalBox); btn = new Button();