From c44c3c4fb4e4784f7b027642cf843141dce5a1b4 Mon Sep 17 00:00:00 2001 From: rYeti Date: Sun, 14 May 2023 01:20:43 +0200 Subject: [PATCH] resolved binding error and added number validator for inputs --- src/stores/storeWeight.js | 12 ++++----- src/views/weight/WeightsInput.vue | 42 +++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/stores/storeWeight.js b/src/stores/storeWeight.js index a7ae186..4e18fd9 100644 --- a/src/stores/storeWeight.js +++ b/src/stores/storeWeight.js @@ -13,13 +13,13 @@ export const useWeightInputStore = defineStore('weightInput', () => { const selectedExercise = ref([]); function addWeightInput(workingSetWeight, workingRepsInput, warmUpSetsWeight, warmUpRepsInput, selectedExerciseInput) { - workingSets.value.push(workingSetWeight); - workingReps.value.push(workingRepsInput); - warmUpSets.value.push(warmUpSetsWeight); - warmUpReps.value.push(warmUpRepsInput); - selectedExercise.value.push(selectedExerciseInput); + workingSets.value = workingSetWeight; + workingReps.value = workingRepsInput; + warmUpSets.value = warmUpSetsWeight; + warmUpReps.value = warmUpRepsInput; + selectedExercise.value = selectedExerciseInput; + } - return { workingSets, workingReps, diff --git a/src/views/weight/WeightsInput.vue b/src/views/weight/WeightsInput.vue index 3b5202d..cb23821 100644 --- a/src/views/weight/WeightsInput.vue +++ b/src/views/weight/WeightsInput.vue @@ -5,14 +5,21 @@
-
+
{{ warmUpSet }}
- +
- +
@@ -22,14 +29,22 @@
-
+
{{ workingset }}
- +
- +
@@ -55,6 +70,7 @@ const warmUpReps = ref([]); const set = ref([]); const weightInput = useWeightInputStore(); + // const warmUpInput = ref([]); // warmUpInput.value = { // warmUpSets: [], @@ -72,7 +88,7 @@ const warmUpAddSet = () => { id: warmUpSetCount++, content: warmUpSetCount.toString().concat('. Set') }; - warmUpSets.value.push(newWarmUpSet.content); + weightInput.warmUpSets.value.push(newWarmUpSet.content); }; const workingAddSet = () => { @@ -80,9 +96,19 @@ const workingAddSet = () => { id: workingSetCount++, content: workingSetCount + ". Set" }; - workingSets.value.push(newWorkingSet.content); + weightInput.workingSets.value.push(newWorkingSet.content); }; +function validateNumber(event, property, index) { + const inputValue = event.target.value; + const isValid = !isNaN(parseFloat(inputValue)) && isFinite(inputValue); + + if (!isValid) { + // If the input is not a valid number, reset the property value to null + weightInput.workingSets.value[index][property] = null; + } + }; + weightInput.addWeightInput(workingSets, workingReps, warmUpSets, warmUpReps, selectedExercise);