You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing error when validating via form options instead of via field #678
When using the (Zod) validator on the form options (passing to useForm) instead of using it directly on the field, there is no entry in the errors/touchedErrors array.
There are two forms in the repro example.
The first form uses a validator on the form.Field. Everything works as expected.
The second form uses a validator on the form options. Now, there is no error.
Expected behavior
Validation errors are put on the errors/touchedErrors field, no matter where validation took place.
Away from a computer right now. Are you checking against the field errors or the form errors. This is a bit confusing, but form validation like this doesn't set field errors, it sets form errors
Are you checking against the field errors or the form errors.
Yep, was using the FieldInfo helper from the examples.
it sets form errors
You're right, the validation message exists on field.form.state.errors, thanks!
This is a bit confusing
I have to agree that this is confusing, as one would always need to look for errors in multiple places.
Also, it seems that the form has no touchedErrors like a Field has?
Helper component for reference:
functionFieldInfo({ field }: {field: FieldApi<any,any,any,any>}){// This is empty when using the "form" validator (but not for the "field" validator)console.log("field touchedErrors",field.state.meta.touchedErrors);// ...but not empty for the form's `errors`console.log("form errors",field.form.state.errors);return(<>{field.state.meta.touchedErrors.length===0 ? ("No errors") : field.state.meta.touchedErrors ? (<em>{field.state.meta.touchedErrors}</em>) : null}</>);}
Activity
crutchcorn commentedon Apr 17, 2024
Away from a computer right now. Are you checking against the field errors or the form errors. This is a bit confusing, but form validation like this doesn't set field errors, it sets form errors
bennettdams commentedon Apr 17, 2024
Yep, was using the
FieldInfohelper from the examples.You're right, the validation message exists on
field.form.state.errors, thanks!I have to agree that this is confusing, as one would always need to look for errors in multiple places.
Also, it seems that the form has no
touchedErrorslike aFieldhas?Helper component for reference:
crutchcorn commentedon Apr 18, 2024
FWIW we're actually planning on removing
touchedErrors😅Also, we're gonna make the story of form->field validation easier here:
#656
Closing as both are a WIP, but thanks for the feedback and detailed report 😇