Skip to content

Validation Logic Fn: event.fieldName seems to always be undefined despite existing in props #1861

@scamden

Description

@scamden

Describe the bug

When writing a validationLogic function I see the types have fieldName on the event and got very excited because I thought it could help me with my use case (described below). But in practice logging that event out, it seems to be undefined in all cases that I checked. Would it be possible to fix?

Use case
Trying to write my own dynamic validation logic to achieve the following:

Validation happens on blur by default (and on submit), but if a given field has errors, dynamic validation happens on change events to that field.

The current dynamic validation logic gets very close to this but it differs in that the change validation only happens after submitting. This feels fine for default submit validation, but when I've chosen "blur" as the default mode, it seems less than ideal. User blurs field and sees error, then the error can't clear again until the blur even if they fix it, but if they happen to be clever enough to click submit after blurring then the errors can clear on change. Feels inconsistent.

I think submit is sorta the wrong pivot point for revalidateLogic personally. I think the real thing we are trying to achieve is to let a user clear errors on change once they see them, which for mode submit is after submit, but for blur it's after blur. Additionally, I don't think I want to see errors reappear on change as user until I trigger the default mode again. That is, whether I've submitted or not, once I clear an error I want to go back to the default mode where I'm not punished on every keystroke. (That is, even in mode: 'submit' , I would want the form to go back to validating on submit once I've cleared the errors from the last submit)

Let me know your thoughts.

Your minimal, reproducible example

this is super easy to repro, but i will add if you request it

Steps to reproduce

  1. Make a tanstack form
  2. Add a custom validationLogic fn
  3. console.log(props.event.fieldName) in that function

Result: It seems never to be defined

Expected behavior

Expected: fieldName is defined when changing particular fields

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: mac
  • Browser: chrome

TanStack Form adapter

None

TanStack Form version

1.25.0

TypeScript version

5.8

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions