From 4465c5ad7c1472c04430924bd36581ea387f92b5 Mon Sep 17 00:00:00 2001 From: Azmi TOUIL <42934070+AzmiTouil@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:04:13 +0100 Subject: [PATCH] fix: Fix validation check for input number - MEED-7842 - Meeds-io/MIPs#154 (#4212) Before this change, there was no validity check of the entry number if it had the same value as the default value 20. --- .../common/components/NumberInput.vue | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/webapp/src/main/webapp/vue-apps/common/components/NumberInput.vue b/webapp/src/main/webapp/vue-apps/common/components/NumberInput.vue index 1fdf1f9e7b0..e046578f684 100644 --- a/webapp/src/main/webapp/vue-apps/common/components/NumberInput.vue +++ b/webapp/src/main/webapp/vue-apps/common/components/NumberInput.vue @@ -104,18 +104,7 @@ export default { }, watch: { num() { - if (!this.initialized) { - return; - } else if (this.min && Number(this.num) < Number(this.min)) { - this.$emit('input', Number(this.min) + this.diff); - this.valid = false; - } else if (this.max && Number(this.num) > Number(this.max)) { - this.$emit('input', Number(this.max) + this.diff); - this.valid = false; - } else { - this.$emit('input', Number(this.num) + this.diff); - this.valid = true; - } + this.handleInputValidation(); }, valid: { immediate: true, @@ -130,6 +119,7 @@ export default { }, mounted() { this.initialized = true; + this.handleInputValidation(); }, methods: { adjust() { @@ -151,6 +141,20 @@ export default { this.num = Number(this.num) + this.step; } }, + handleInputValidation() { + if (!this.initialized) { + return; + } else if (this.min && Number(this.num) < Number(this.min)) { + this.$emit('input', Number(this.min) + this.diff); + this.valid = false; + } else if (this.max && Number(this.num) > Number(this.max)) { + this.$emit('input', Number(this.max) + this.diff); + this.valid = false; + } else { + this.$emit('input', Number(this.num) + this.diff); + this.valid = true; + } + } }, };