T
TanStack2w ago
vicious-gold

How to use form validation through Schema Libraries ?

But that each are validated indiidually onChange/Onblur, but not all field at once like it is by default?
6 Replies
flat-fuchsia
flat-fuchsia2w ago
hide the errors unless the field is touched / blurred using the field meta
vicious-gold
vicious-goldOP2w ago
interesting... but at the same time, i want all the errors to appears if the user click the submit button
flat-fuchsia
flat-fuchsia2w ago
form.submissionAttempts keeps track of how many times the user has tried, even if it failed. So if it's larger than 0, that also works alternatively, you can use revalidateLogic so that it waits until a first submission before using it. I can link the docs to that if you'd like
vicious-gold
vicious-goldOP2w ago
ok, i think i got it working with field.form.state.isSubmitting
flat-fuchsia
flat-fuchsia2w ago
that's only while it is submitting, which means it goes back to false if it encountered an error what likely happened is that it touched all fields during the submission
vicious-gold
vicious-goldOP2w ago
I do like this
const isError = field.form.state.isSubmitting
? !field.state.meta.isValid
: field.state.meta.isDirty && !field.state.meta.isValid;
const isError = field.form.state.isSubmitting
? !field.state.meta.isValid
: field.state.meta.isDirty && !field.state.meta.isValid;

Did you find this page helpful?