From f51284e4ea42dc101fe676b9a1c2de30624e8376 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sat, 12 Aug 2023 15:30:47 +1200 Subject: [PATCH] Validate and fix numbers in StartPlan --- StartPlan.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/StartPlan.tsx b/StartPlan.tsx index e4c69ac..9746e4c 100644 --- a/StartPlan.tsx +++ b/StartPlan.tsx @@ -14,6 +14,7 @@ import { PADDING } from "./constants"; import CountMany from "./count-many"; import { AppDataSource } from "./data-source"; import { getNow, setRepo, settingsRepo } from "./db"; +import { fixNumeric } from "./fix-numeric"; import GymSet from "./gym-set"; import { PlanPageParams } from "./plan-page-params"; import Settings from "./settings"; @@ -129,7 +130,12 @@ export default function StartPlan() { label="Reps" keyboardType="numeric" value={reps} - onChangeText={setReps} + onChangeText={(newReps) => { + const fixed = fixNumeric(newReps); + setReps(fixed); + if (fixed.length !== newReps.length) + toast("Reps must be a number"); + }} onSubmitEditing={() => weightRef.current?.focus()} selection={selection} onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} @@ -139,7 +145,12 @@ export default function StartPlan() { label="Weight" keyboardType="numeric" value={weight} - onChangeText={setWeight} + onChangeText={(newWeight) => { + const fixed = fixNumeric(newWeight); + setWeight(fixed); + if (fixed.length !== newWeight.length) + toast("Weight must be a number"); + }} onSubmitEditing={handleSubmit} innerRef={weightRef} blurOnSubmit