diff --git a/src/components/ADempiere/Field/FieldNumber.vue b/src/components/ADempiere/Field/FieldNumber.vue
index 304410e3..199b0613 100644
--- a/src/components/ADempiere/Field/FieldNumber.vue
+++ b/src/components/ADempiere/Field/FieldNumber.vue
@@ -38,7 +38,7 @@ export default {
value: value,
showControls: true,
operation: '',
- expression: /[^\d\/.()%\*\+\-]/gim,
+ expression: /[\d\/.()%\*\+\-]/gim,
valueToDisplay: '',
isShowed: false
}
@@ -90,31 +90,55 @@ export default {
return Number(value)
},
calculateValue(event) {
- const result = this.calculationValue(this.value, event)
- if (!this.isEmptyValue(result)) {
- this.valueToDisplay = result
- this.isShowed = true
+ const isAllowed = event.key.match(this.expression)
+ if (isAllowed) {
+ const result = this.calculationValue(this.value, event)
+ if (!this.isEmptyValue(result)) {
+ this.valueToDisplay = result
+ this.isShowed = true
+ } else {
+ this.valueToDisplay = '...'
+ this.isShowed = true
+ }
+ } else if (!isAllowed && event.key === 'Backspace') {
+ if (String(this.value).slice(0, -1) > 0) {
+ event.preventDefault()
+ const newValue = String(this.value).slice(0, -1)
+ const result = this.calculationValue(newValue, event)
+ if (!this.isEmptyValue(result)) {
+ this.value = this.validateValue(result)
+ this.valueToDisplay = result
+ this.isShowed = true
+ } else {
+ this.valueToDisplay = '...'
+ this.isShowed = true
+ }
+ }
+ } else if (!isAllowed && event.key === 'Delete') {
+ if (String(this.value).slice(-1) > 0) {
+ event.preventDefault()
+ const newValue = String(this.value).slice(-1)
+ const result = this.calculationValue(newValue, event)
+ if (!this.isEmptyValue(result)) {
+ this.value = this.validateValue(result)
+ this.valueToDisplay = result
+ this.isShowed = true
+ } else {
+ this.valueToDisplay = '...'
+ this.isShowed = true
+ }
+ }
} else {
- this.valueToDisplay = '...'
- this.isShowed = true
+ event.preventDefault()
}
},
changeValue() {
- const result = this.validateValue(this.valueToDisplay)
- this.$store.dispatch('notifyFieldChange', {
- isAdvancedQuery: this.metadata.isAdvancedQuery,
- panelType: this.metadata.panelType,
- parentUuid: this.metadata.parentUuid,
- containerUuid: this.metadata.containerUuid,
- columnName: this.metadata.columnName,
- newValue: result,
- field: this.metadata,
- isChangedOldValue: true
- })
- .finally(() => {
- this.clearVariables()
- this.isShowed = false
- })
+ if (!this.isEmptyValue(this.valueToDisplay) && this.valueToDisplay !== '...') {
+ const result = this.validateValue(this.valueToDisplay)
+ this.preHandleChange(result)
+ }
+ this.clearVariables()
+ this.isShowed = false
}
}
}
diff --git a/src/components/ADempiere/Field/index.vue b/src/components/ADempiere/Field/index.vue
index a5acc6d4..c9ba1fc5 100644
--- a/src/components/ADempiere/Field/index.vue
+++ b/src/components/ADempiere/Field/index.vue
@@ -44,7 +44,7 @@
:record-uuid="field.recordUuid"
/>
diff --git a/src/components/ADempiere/Field/popover/calculator.vue b/src/components/ADempiere/Field/popover/calculator.vue
index db8e0e3e..9d524d07 100644
--- a/src/components/ADempiere/Field/popover/calculator.vue
+++ b/src/components/ADempiere/Field/popover/calculator.vue
@@ -1,10 +1,11 @@
-
+
{
this.clearVariables()
+ this.$children[0].visible = false
})
},
spanMethod({ row, column, rowIndex, columnIndex }) {
@@ -264,7 +285,7 @@ export default {
}
}
} else if (rowIndex === 4) {
- if (row[column.property].value === 0) {
+ if (row[column.property].value === '0') {
return {
rowspan: 1,
colspan: 2
@@ -292,6 +313,9 @@ export default {
} else {
this.valueToDisplay = '...'
}
+ },
+ focusCalc() {
+ this.$refs.calculatorInput.focus()
}
}
}
diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js
index 09015628..41bb38c4 100644
--- a/src/utils/ADempiere/valueUtils.js
+++ b/src/utils/ADempiere/valueUtils.js
@@ -388,10 +388,12 @@ export function tagStatus(tag) {
let partialValue = ''
export function calculationValue(value, event) {
- const VALIDATE_EXPRESSION = /[^\d\/.()%\*\+\-]/gim
- if (!this.isEmptyValue(event) && !VALIDATE_EXPRESSION.test(event.key)) {
+ const isZero = Number(value) === 0
+ const VALIDATE_EXPRESSION = /[\d\/.()%\*\+\-]/gim
+ const isValidKey = VALIDATE_EXPRESSION.test(event.key)
+ if (event.type === 'keydown' && isValidKey) {
partialValue += event.key
- const operation = String(value) + partialValue
+ const operation = isEmptyValue(value) || isZero ? partialValue : String(value) + partialValue
if (!isEmptyValue(operation)) {
try {
// eslint-disable-next-line no-eval
@@ -400,9 +402,23 @@ export function calculationValue(value, event) {
return null
}
}
+ } else if (event.type === 'click') {
+ if (!isEmptyValue(value)) {
+ try {
+ // eslint-disable-next-line no-eval
+ return eval(value) + ''
+ } catch (error) {
+ return null
+ }
+ }
} else {
- if (value.key === 'Backspace') {
- partialValue = partialValue.slice(0, -1)
+ if ((event.key === 'Backspace' || event.key === 'Delete') && !isEmptyValue(value)) {
+ try {
+ // eslint-disable-next-line no-eval
+ return eval(value) + ''
+ } catch (error) {
+ return null
+ }
} else {
return null
}