Validation onSubmit does not re-trigger with conditionally rendered fields

Đang mở
#1,874 3 bình luận 3 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
react, typescript
Lĩnh vực
frontend, testing

Hướng nghiên cứu

Bắt đầu với bản tái hiện tối thiểu StackBlitz được liên kết và làm theo trình tự gửi: gửi một lần, thay đổi trường điều kiện, sau đó gửi lại. Theo dõi luồng xác thực biểu mẫu React và so sánh hành vi của onSubmit với onChange; hoàn tất khi lần gửi thứ hai xác thực nhất quán trường vừa được render.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

v1 v2: needs investigation
Describe the bug

The onSubmit validator is not re-triggering after first time when a "dynamic" field has changed. In this case I'm using Zod's discriminated union to decide whether to show this or that field, but this bug happens also when using for example a superRefine to conditionally validate a field. The first submit triggers correctly the onSubmit validator, but then if we change the field and show the other input field and submit again, it does not work trigger the validator. Even with canSubmitWhenInvalid: true.

There is a similar issue #1780 that points to this error but it's not actually the same. In that issue the author resolved the issue just putting canSubmitWhenInvalid: true, but actually the problem we have found is in the validation not getting triggered.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-q2pndiqf?file=src%2Findex.tsx

Steps to reproduce
  1. Click on Submit -> Should show the error for thisField
  2. Change the Select to the value That
  3. Click again on Submit -> Should show the error for thatField, but it does not.

If we change the validators to run on onChange, it works!
It works also if after submitting you change an input or on blur.

Expected behavior

I would expect that the onSubmit validator would run on submitting the form and it would have the same result of the onChange schema validation

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform
  • OS: MacOS
  • Browser: Chrome
  • Version: 142.0.7444.60
TanStack Form adapter

react-form

TanStack Form version

1.25.0

TypeScript version

5.9.3

Additional context

No response

Ngôn ngữ chính
TypeScript
Star
6.8k
Fork
717
Merge trung bình
5 ngày 22 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/form

Tất cả issue của TanStack/form

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.