How to get data from a backend api validation in the onSubmit?
I'm migrating an app from Conform to Tanstack Form, and i had this kind of validation
if the api returned an error i was invalidating the form with the api error message, but if there was no error i was populating the form data with the api returned data, so i can use it later, now im trying to do something like that in the ts form, but i cant find a way to do it
3 Replies
inland-turquoiseOP•6mo ago
i achieve something similar with this:
but this useState just feels wrong, i think i should be able to populate the onSubmit data from the onSubmitAsync validator, am i missing something?
foreign-sapphire•6mo ago
onSubmit cannot be reached if onSubmitAsync errored. Therefore, it should be considered an "onSuccess listener" of your form.
Now usually, this is good enough, but in your case you want to share data between the two. It's not needed because you can replace your setState action with the actual action of your form:
inland-turquoiseOP•6mo ago
it makes sense, thanks a lot!