-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[✨] complex form should not flatten errors #5463
Labels
Comments
@ulic75 I created an issue so maybe someone can check this out. |
@wmertens do you have an opinion on this? |
What we are doing is skipping zod and doing this: export const useMyCoolAction = routeAction$(async (rawData, event) => {
try {
const data = someSchema.parse(rawData);
} catch (error) {
if (error instanceof z.ZodError) {
event.fail(400, flattenZodIssues(error.issues));
}
}
}); The flattenZodIssue: export default function flattenZodIssues(issues: z.ZodIssue | z.ZodIssue[]) {
issues = Array.isArray(issues) ? issues : [issues];
return issues.reduce((acc, issue) => {
acc[issue.path.join('.')] = issue.message;
return acc;
}, {} as Record<string, string>);
}
export type FlattenZodIssues = ReturnType<typeof flattenZodIssues>; |
tzdesign
pushed a commit
to tzdesign/qwik
that referenced
this issue
Jun 18, 2024
On very complex nested types, you loose the location or the field the error belongs to. Closes QwikDev#5463 BREAKING CHANGE: The fieldErrors type on the action changed from Record<string,string[]> (simplified) to Record<string,string> where the key is now dot notation closes QwikDev#5463
7 tasks
gioboa
added a commit
that referenced
this issue
Jul 9, 2024
* feat(qwikcity/actions): dotnotation field-errors On very complex nested types, you loose the location or the field the error belongs to. Closes #5463 BREAKING CHANGE: The fieldErrors type on the action changed from Record<string,string[]> (simplified) to Record<string,string> where the key is now dot notation closes #5463 * fix types and adding test * make the type partial * introduce arrays to the type and flattenErrors * run api.update * chore: run api.update * chore: run api.update * adding array to the test --------- Co-authored-by: Tobias Zimmermann <[email protected]> Co-authored-by: gioboa <[email protected]> Co-authored-by: PatrickJS <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Is your feature request related to a problem?
We have a complex Zod Type for cart.
If an error occurs in one of the fields at the lowest level like:
The errors are flatten within cart:
Example multiple fields:
SEE: #4634
Describe the solution you'd like
We need to access the specific fields with the path.
Describe alternatives you've considered
We either have to overwrite the types so that the errors are not flattened for complex forms or we send the errors unflattened in a second field.
Additional context
No response
The text was updated successfully, but these errors were encountered: