TanStackT
TanStackβ€’5mo agoβ€’
29 replies
moderate-tomato

Programmatically clear errors on specific (array) fields

Hello again!

I'm running into a very specific problem on my TSF app. I created a simplified version of it on StackBlitz so it illustrates my problem a little better: https://stackblitz.com/edit/reset-tsf-errors?file=src%2Findex.tsx

I have an array of fields and we can't have duplicate values in there. Whenever we try submitting the form and this rule is not fulfilled, we should highlight which fields are dupes. For example:
βœ… GOOD - infos = [1, 2, 3, 4]
❌ ERROR- infos = [1, 2, 1, 4] - 1 is duplicate, so we would highlight positions 0 and 2, saying we can't have duplicate info.
(check the image for an illustration)

The thing is: let's say I change position 0 to "3". Everything would be fine -> But the submit button is still disabled, because it assumes the index2 is still "wrong", since I haven't changed it.

So my question is: Is there a way of resetting the error on other array fields, when I fix one of the incorrect fields?
If I could "reset" all array field errors when one of the inputs changes, it would already be very helpful.

Thanks in advance! πŸ’™
image.png
StackBlitzseab
Run official live example code for Form Field Errors From Form Validators, created by Tanstack on StackBlitz
Reset TSF errors - StackBlitz
Was this page helpful?