running-tools

A collection of tools for runners and their coaches
git clone https://git.ashermorgan.net/running-tools/
Log | Files | Refs | README

commit d4a88bbe5db2987edf0a314f78baca0d85df60ca
parent 4170dda0e2989405f780e3ca75d13f26adfa7a4c
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Sat, 17 May 2025 17:51:48 -0700

Fix early formatting bug in Decimal & IntegerInput

Previously, input such as "0.1" would be replaced with "0.10"
immediately, rather than after the next blur event.

Diffstat:
Msrc/components/DecimalInput.vue | 10++--------
Msrc/components/IntegerInput.vue | 10++--------
2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/src/components/DecimalInput.vue b/src/components/DecimalInput.vue @@ -57,25 +57,19 @@ const inputElement = ref(null); * Update the internal value when the component value changes */ watch(model, (newValue) => { - if (newValue !== internalValue.value) { + if (Math.abs(newValue - internalValue.value) > 0.00001) { internalValue.value = newValue; stringValue.value = format(internalValue.value); } }); /** - * Update the component value when the internal value changes - */ -watch(internalValue, (newValue) => { - model.value = newValue; -}); - -/** * Update the internal value when the raw string value changes */ watch(stringValue, (newValue) => { if (inputElement.value.validity.valid) { internalValue.value = Number(newValue); + model.value = internalValue.value; } }); diff --git a/src/components/IntegerInput.vue b/src/components/IntegerInput.vue @@ -45,25 +45,19 @@ const inputElement = ref(null); * Update the internal value when the component value changes */ watch(model, (newValue) => { - if (newValue !== internalValue.value) { + if (Math.abs(newValue - internalValue.value) > 0.00001) { internalValue.value = newValue; stringValue.value = format(internalValue.value); } }); /** - * Update the component value when the internal value changes - */ -watch(internalValue, (newValue) => { - model.value = newValue; -}); - -/** * Update the internal value when the raw string value changes */ watch(stringValue, (newValue) => { if (inputElement.value.validity.valid) { internalValue.value = Number(newValue); + model.value = internalValue.value; } });