Skip to content
Source
Sign inSign up
TanStack/form

Field's `isTouched` state being updated without being touched #2101

ClosedHM-23-HM(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

I'm building a multi-step form, and when I press the 'Next' button the isTouched state for the field in the second step of the form changes from false to true after being rendered, and without the field being touched. This happens with or without inter-step validation. What am I missing?

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-rkntekfw?file=src%2FApp.tsx

Steps to reproduce

  1. Enter any string gte to 2 chars in length for the first name.
  2. Press "Next".

Expected behavior

I'm expecting isTouched to remain false for the field in the second step of the form.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

OS: Windows, Browser: Google Chrome and Microsoft Edge

TanStack Form adapter

react-form

TanStack Form version

1.28.5

TypeScript version

5.9.3

Additional context

No response

  1. I have same.

    1. Enter name.
    2. Tab -> start writing = Error appears. Image
    const form = useAppForm({
        defaultValues,
        validators: {
          onBlur: schema,
          onSubmit: schema,
        },
        onSubmit: ({ value }) => {
          alert(JSON.stringify(value, null, 2));
        },
      });
  2. In your demo, it looks like the "Next" button is still triggering the onSubmit handler for the form. This is more-so something to do with react and the way you're conditionally rendering the buttons (read more about why here). To fix this, simply add unique keys to the buttons: Image or call event.preventDefault() in the onClick callback for the button before calling next()

Sign in to join this conversation.