From 47f84941937a85737ccc1121a7e86710f2541ce3 Mon Sep 17 00:00:00 2001 From: Vishnu Sreekumaran Nair <200557136@student.georgianc.on.ca> Date: Tue, 6 May 2025 14:29:59 -0400 Subject: [PATCH] update handlechange to modify form validation logic --- client/src/Pages/Settings/index.jsx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/client/src/Pages/Settings/index.jsx b/client/src/Pages/Settings/index.jsx index 456e620ff..64607648d 100644 --- a/client/src/Pages/Settings/index.jsx +++ b/client/src/Pages/Settings/index.jsx @@ -94,12 +94,17 @@ const Settings = () => { return; } + let inputValue = value; + if (id === "ttl") { + inputValue = value.replace(/[^0-9]/g, ""); + } + + const updatedForm = { ...form, [id]: inputValue }; const { error } = settingsValidation.validate( - { [id]: value }, - { - abortEarly: false, - } + updatedForm, + { abortEarly: false } ); + if (!error || error.details.length === 0) { setErrors({}); } else { @@ -110,12 +115,8 @@ const Settings = () => { setErrors(newErrors); logger.error("Validation errors:", error.details); } - let inputValue = value; - id === "ttl" && (inputValue = value.replace(/[^0-9]/g, "")); - setForm((prev) => ({ - ...prev, - [id]: inputValue, - })); + + setForm(updatedForm); }; // TODO Handle saving