T
TanStack7mo ago
deep-jade

should blur trigger onChange validation?

Hey there, appreciate the library, was doing some form work and noticed I'm getting onChange validation errors when clicking into and then out of a field (but without changing the value). Looking at the code it seems like if a field was never previously touched, then blurring the field causes the "change" validation to run. Does this seem accurate? Did I miss something in the docs re: this behavior? https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1602
GitHub
form/packages/form-core/src/FieldApi.ts at main · TanStack/form
🤖 Headless, performant, and type-safe form state management for TS/JS, React, Vue, Angular, Solid, and Lit. - TanStack/form
4 Replies
deep-jade
deep-jadeOP7mo ago
for context we were only showing errors when fields are touched AND dirty, and because the blur event isn't dirty-ing the field we end up in a weird state where the field has errors (from the onChange validation running) but is also not dirty and is pristine (though it is touched, which I reckon I can use to extend our show errors logic)
ambitious-aqua
ambitious-aqua7mo ago
This is strange, I am seeing this behavior as well. I'm pretty confident blurring the input should not be firing the validation. Can you please open an issue?
ambitious-aqua
ambitious-aqua7mo ago
Actually I do see that we intentionally trigger onChange when blurring IF the field is not touched. Not sure on the logic behind this? https://github.com/TanStack/form/blob/8672e57a7bea0a7318435d29d22c321d465e0213/packages/form-core/src/FieldApi.ts#L1600
GitHub
form/packages/form-core/src/FieldApi.ts at 8672e57a7bea0a7318435d29...
🤖 Headless, performant, and type-safe form state management for TS/JS, React, Vue, Angular, Solid, and Lit. - TanStack/form
deep-jade
deep-jadeOP7mo ago
ya seemed intentional looking at the code, but was a surprise as we end up with an onChange error in the errorMap but nothing changed (only blurred), so figured I'd mention it happy to open an issue if that seems appropriate, else maybe just a docs update would be helpful for future form-ers if its desired behavior

Did you find this page helpful?