TanStackT
TanStack16mo ago
6 replies
popular-magenta

Validation that returns additional data

I have a validation that returns additional data and I'm not sure where to put it best.

I collect an Address: (Street, PostalCode, City) - I run basic validations against it onChange (fields are required)

onSubmit I run the onSubmitAsync validator on the FormApi - this makes a call against the Backend and returns an array of possible address matches for what the user entered.

[
  {
    street: "Mainstreet 1",
    postalCode: "123",
    city: "Paris",
    id: "4711" // <----- this is what i need later on
  },
  {
    // … another address …
  },
]


Multiple Adresses => Invalid => user needs to select one of them
No Adress => Invalid => user needs to enter a different address
1 Match => Valid => remember the id as it's needed in onSubmit to pass it on to the following process

Where would you put the id? into the form as a hidden input? into a useState? ?
Was this page helpful?