Skip to content

Commit

Permalink
fix: only show errors when field not in focus, closes #3766
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Jul 19, 2023
1 parent 0e73a1e commit abffd71
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/common/form-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export function useShowFieldError(name: string) {
const form = useFormikContext();
const [_, meta] = useField(name);
const isDirty = useIsFieldDirty(name);
const isFieldInFocus = document.activeElement?.getAttribute('name') === name;

return (form.submitCount > 0 && meta.error) || (meta.touched && isDirty && meta.error);
return (
(form.submitCount > 0 && meta.error) ||
(!isFieldInFocus && meta.touched && isDirty && meta.error)
);
}

0 comments on commit abffd71

Please sign in to comment.