From a3ff181b6edd1d65fc79b585af423b0c85a33c0c Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 25 Sep 2024 23:17:55 +0800 Subject: [PATCH] not allow to input non number to the amount input box in desktop version via mobile device --- src/components/desktop/AmountInput.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/desktop/AmountInput.vue b/src/components/desktop/AmountInput.vue index d89d2138..ea3d97ff 100644 --- a/src/components/desktop/AmountInput.vue +++ b/src/components/desktop/AmountInput.vue @@ -137,7 +137,25 @@ export default { } }, 'currentValue': function (newValue) { - this.$emit('update:modelValue', this.$locale.parseAmount(this.userStore, newValue)); + let finalValue = ''; + + if (newValue) { + const decimalSeparator = this.$locale.getCurrentDecimalSeparator(this.userStore); + + for (let i = 0; i < newValue.length; i++) { + if (!('0' <= newValue[i] && newValue[i] <= '9') && newValue[i] !== '-' && newValue[i] !== decimalSeparator) { + break; + } + + finalValue += newValue[i]; + } + } + + if (finalValue !== newValue) { + this.currentValue = finalValue; + } else { + this.$emit('update:modelValue', this.$locale.parseAmount(this.userStore, finalValue)); + } } }, methods: {