errorMessagesForSchema returns wrong data
See original GitHub issue const securityUpdateAction = useActionData<typeof action>() as any;
if (securityUpdateAction) {
const errorMessagesFormattedByDf = errorMessagesForSchema(
securityUpdateAction.inputErrors,
Schema
);
}
The securityUpdateAction
returns inputErrors
with this shape:
[
{
"path": [
"newPassword"
],
"message": "String must contain at least 8 character(s)"
},
{
"path": [
"newPasswordRepeat"
],
"message": "String must contain at least 8 character(s)"
},
{
"path": [
"newPassword",
"newPasswordRepeat"
],
"message": "Passwords don't match"
}
]
The Schema
looks like this:
const Schema = z
.object({
oldPassword: z.string(),
newPassword: z.string().min(8),
newPasswordRepeat: z.string().min(8),
})
.refine((data) => data.newPassword === data.newPasswordRepeat, {
message: "Passwords don't match",
path: ["newPassword", "newPasswordRepeat"], // path of error
})
The output after parsing looks like this in the browser console:
In the docs it shows the shape what is to be expected: https://github.com/SeasonedSoftware/domain-functions#errormessagesforschema
errorForSchema(result.inputErrors, schema)
/*
{
email: ['Must not be empty', 'Must be a string'],
password: ['Must not be empty']
}
*/
Basically: Record<string,string[]>
Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Can you get good error messages for schema validaiton, on ...
Hi there. My objective is to upgrade an existing mongo database to enforce schemas. Reading this blog, it seems like version 5 actually ......
Read more >Warning and error messages for schema validation in ...
Warning and error messages for schema validation in Instance Data Replication (IDR) ... Some information is incorrect or missing.
Read more >domain-functions/README.md at main - GitHub
Given a array of SchemaError be it from inputErrors or environmentErrors and a name, it returns a list of error messages with that...
Read more >Release Notes (mandatory)
Fixed the issue where incorrect error message was returned for Appointment ... with unexpected error message and no error messages for schema validation...
Read more >SAP ABAP Message Class 5P (Error Messages for Schema ...
SAP ABAP Message Class 5P (Error Messages for Schema, Pers.Calc.Rule and Feature Checks) - SAP ... PBAS (Package) SAP HR Master Data Application...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
i can confirm, this produces the wanted behaviour
@diogob interesting, i had used the same schema before with zod’s
flatten()
method, and it worked nicely. It added the refinement error for both fields, so in the UI I had the error displayed under both inputs. How can I achieve the same result witherrorMessagesForSchema()
? Do I have to use therefine()
twice? changing the path for the second refinement?