Fix SendouForm not scrolling to errors from server
Some checks failed
E2E Tests / e2e (push) Has been cancelled
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled

This commit is contained in:
Kalle 2026-02-18 22:03:48 +02:00
parent 336a9aaed5
commit ddd9b184aa

View File

@ -130,14 +130,27 @@ export function SendouForm<T extends z.ZodRawShape>({
React.useLayoutEffect(() => {
const serverFieldErrors = fetcher.data?.fieldErrors ?? {};
for (const [fieldName, errorMessage] of Object.entries(serverFieldErrors)) {
const errorEntries = Object.entries(serverFieldErrors);
if (errorEntries.length === 0) {
setFallbackError(null);
return;
}
for (const [fieldName, errorMessage] of errorEntries) {
const errorElement = document.getElementById(errorMessageId(fieldName));
if (!errorElement) {
setFallbackError(`${t(errorMessage as never)} (${fieldName})`);
return;
}
}
setFallbackError(null);
const firstErrorField = errorEntries[0][0];
const firstErrorElement = document.getElementById(
errorMessageId(firstErrorField),
);
firstErrorElement?.scrollIntoView({ behavior: "smooth", block: "center" });
}, [fetcher.data, t]);
const serverErrors = visibleServerErrors as Partial<