T
TanStack3mo ago
sensitive-blue

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
correct-apricot
correct-apricot3mo ago
hide the errors unless the field is touched / blurred using the field meta
sensitive-blue
sensitive-blueOP3mo ago
interesting... but at the same time, i want all the errors to appears if the user click the submit button
correct-apricot
correct-apricot3mo 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
sensitive-blue
sensitive-blueOP3mo ago
ok, i think i got it working with field.form.state.isSubmitting
correct-apricot
correct-apricot3mo 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
sensitive-blue
sensitive-blueOP3mo 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?