T
TanStack•2h ago
conventional-tan

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! šŸ’™
seab
StackBlitz
Reset TSF errors - StackBlitz
Run official live example code for Form Field Errors From Form Validators, created by Tanstack on StackBlitz
No description
2 Replies
adverse-sapphire
adverse-sapphire•2h ago
Can you perform the duplicate-check onChange? Maybe you can move the validation to the Form-Level? Combined with this
revalidateLogic({
mode: 'submit',
modeAfterSubmission: 'change',
}),
revalidateLogic({
mode: 'submit',
modeAfterSubmission: 'change',
}),
https://tanstack.com/form/latest/docs/framework/react/guides/dynamic-validation#revalidation-options
conventional-tan
conventional-tanOP•2h ago
That revalidationLogic is the default, which I am using. About the duplicate-check onChange, I really need to have it done onSubmit, because on my app we have the Backend doing more computations around it and returning which fields are erroring. (I used a simple duplicate-check here to simulate a basic Backend validation)

Did you find this page helpful?