Merged in fix/SW-2679-form-tracking (pull request #2455)

fix(SW-2679): dont track form abandonment if form is valid

* fix(SW-2679): dont track form abandonment if form is valid


Approved-by: Linus Flood
This commit is contained in:
Tobias Johansson
2025-06-27 06:26:43 +00:00
parent 6965effcc2
commit 57433c0395

View File

@@ -331,7 +331,7 @@ export function useFormTracking<T extends FieldValues>(
}, [subscribe, formType, nameSuffix, formStarted])
useEffect(() => {
if (!formStarted || !lastAccessedField.current) return
if (!formStarted || !lastAccessedField.current || formState.isValid) return
const lastField = lastAccessedField.current
@@ -352,5 +352,5 @@ export function useFormTracking<T extends FieldValues>(
window.removeEventListener("beforeunload", handleBeforeUnload)
window.removeEventListener("visibilitychange", handleVisibilityChange)
}
}, [formStarted, formType, nameSuffix])
}, [formStarted, formType, nameSuffix, formState.isValid])
}