From cfcb23fefb11af3eb4f2263410f559ca03c1890b Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 2 Apr 2026 08:18:57 -0500 Subject: [PATCH] fix validation for speed estimation --- web/src/components/settings/ZoneEditPane.tsx | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/web/src/components/settings/ZoneEditPane.tsx b/web/src/components/settings/ZoneEditPane.tsx index 18e7c9105f..ef9a3c3cba 100644 --- a/web/src/components/settings/ZoneEditPane.tsx +++ b/web/src/components/settings/ZoneEditPane.tsx @@ -293,7 +293,7 @@ export default function ZoneEditPane({ const form = useForm>({ resolver: zodResolver(formSchema), - mode: "onBlur", + mode: "onChange", defaultValues: { name: polygon?.name ?? "", friendly_name: polygon?.friendly_name ?? polygon?.name ?? "", @@ -314,18 +314,25 @@ export default function ZoneEditPane({ }, }); + const watchSpeedEstimation = form.watch("speedEstimation"); + const watchLineA = form.watch("lineA"); + const watchLineB = form.watch("lineB"); + const watchLineC = form.watch("lineC"); + const watchLineD = form.watch("lineD"); + + const canSave = + form.formState.isValid && + (!watchSpeedEstimation || + (!!watchLineA && !!watchLineB && !!watchLineC && !!watchLineD)); + useEffect(() => { - if ( - form.watch("speedEstimation") && - polygon && - polygon.points.length !== 4 - ) { + if (watchSpeedEstimation && polygon && polygon.points.length !== 4) { toast.error( t("masksAndZones.zones.speedThreshold.toast.error.pointLengthError"), ); form.setValue("speedEstimation", false); } - }, [polygon, form, t]); + }, [polygon, form, t, watchSpeedEstimation]); const saveToConfig = useCallback( async ( @@ -966,7 +973,7 @@ export default function ZoneEditPane({