Did errors changed? #1284
-
I've recently updated to v1. But now my errors look like: the error in black is this code (like in the example):
and the red one is a separate component:
This is the field.state.meta.errors array: The array is apparently no longer flat, but consists of objects. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
Yes, we were previously only returning the This should bring back the old behaviour: -field.state.meta.errors.join(',')
+field.state.meta.errors.map(error => error.message).join(',') |
Beta Was this translation helpful? Give feedback.
-
I have ui components expecting a list of errors per field. Any better solution than piping everything through: const adaptErrors = (errors: Array<StandardSchemaV1Issue | undefined>) =>
errors.filter((error) => error !== undefined).map((error) => error.message); I in particular don't like that undefined and I don't understand why that's needed…? I'm using valibot, very basic usage: import { StandardSchemaV1Issue, useForm } from "@tanstack/react-form";
import * as v from "valibot";
const schema = v.object({
name: v.pipe(v.string(), v.nonEmpty("Please provide name"))
});
export default function AReactComponent() {
const form = useForm({
defaultValues: {
name: ""
},
validators: {
onChange: schema
}
});
return (
<form.Field name="name">
{(field) => (
<>
<input id={field.name} type="text" defaultValue={field.state.value} />
<ErrorComponent errors={field.state.meta.errors} />
</>
)}
</form.Field>
);
}
type Errors = string[]; // Type 'undefined' is not assignable to type 'string'.
type Errors2 = Array<string | undefined>; // Type 'StandardSchemaV1Issue' is not assignable to type 'string'.
type Errors3 = Array<StandardSchemaV1Issue | undefined>; // Works
const ErrorComponent = ({ errors }: { errors: Errors3 }) => {
return errors.join(", ");
}; |
Beta Was this translation helpful? Give feedback.
-
Thanks! I will take a look later today.
…On Fri, Mar 28, 2025 at 9:57 AM Leonardo Montini ***@***.***> wrote:
All you need to know about docs:
https://github.com/TanStack/form/blob/main/CONTRIBUTING.md#editing-the-docs-locally-and-previewing-the-changes
Let me know if something is missing/unclear!
—
Reply to this email directly, view it on GitHub
<#1284 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA7ZLXLME6NAWSRZXWUKHL2WVWNXAVCNFSM6AAAAABZCSEZZCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENRVGU3TEOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Yes, we were previously only returning the
message
field of Standard Schema errors, while now you have control over the entire error object.This should bring back the old behaviour: