Skip to content

Discriminated unions + conditionally rendered fields #1780

@pifantastic

Description

@pifantastic

Describe the bug

When using discriminated unions and conditionally rendered fields, it's possible to get into a bad state.

It's a bit hard to explain, so see the reproduction steps + stackblitz.

It's possible that there is a better approach here that I don't see. Very open to that.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-ccufpzmq?file=src%2Findex.tsx,package.json&preset=node

Steps to reproduce

  1. Click submit
  2. Note the validation error "thisField is required"
  3. Switch from "this" to "that"
  4. Note the Submit button is disabled and no validation errors are present

Expected behavior

Either the submit button should be enabled so that the user can submit the form and see validation errors, or validation should trigger automatically.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome

TanStack Form adapter

react-form

TanStack Form version

1.23.4

TypeScript version

No response

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