Skip to content

Commit

Permalink
feat(validation): return submittedData to client
Browse files Browse the repository at this point in the history
  • Loading branch information
chohner committed Nov 17, 2023
1 parent b2c1b27 commit 9ef99bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/routes/beratungshilfe.zustaendiges-gericht.suche.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function loader({ request }: LoaderFunctionArgs) {

export async function action({ request }: ActionFunctionArgs) {
const result = await validatorServer.validate(await request.formData());
if (result.error) return validationError(result.error);
if (result.error) return validationError(result.error, result.submittedData);
const { pathname } = new URL(request.url);
const urlStem = pathname.substring(0, pathname.lastIndexOf("/"));
return redirect(`${urlStem}/ergebnis/${result.data?.postcode}`);
Expand Down
2 changes: 1 addition & 1 deletion app/routes/kitchensink._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {

export const action = async ({ request }: DataFunctionArgs) => {
const data = await validator.validate(await request.formData());
if (data.error) return validationError(data.error);
if (data.error) return validationError(data.error, data.submittedData);
return json(data.data);
};

Expand Down
6 changes: 5 additions & 1 deletion app/routes/shared/step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ export const action = async ({ params, request }: ActionFunctionArgs) => {
Object.keys(relevantFormData),
);
const validationResult = await validator.validate(relevantFormData);
if (validationResult.error) return validationError(validationResult.error);
if (validationResult.error)
return validationError(
validationResult.error,
validationResult.submittedData,
);

updateSession(flowSession, validationResult.data);

Expand Down

0 comments on commit 9ef99bd

Please sign in to comment.