Validation onSubmit does not re-trigger with conditionally rendered fields
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- react, typescript
调研方向
从链接的 StackBlitz 最小复现开始,并遵循提交顺序:提交一次,更改条件字段,然后再次提交。跟踪 React 表单验证路径,并比较 onSubmit 与 onChange 的行为;当第二次提交能够一致地验证新渲染的字段时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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
- Click on Submit -> Should show the error for
thisField - Change the Select to the value That
- 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
- 主要语言
- TypeScript
- 星标
- 6.8k
- 派生
- 717
- 平均合并
- 5 天 22 小时
- 30 天内合并 PR
- 14
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/form 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
Submit listener exceptions leave isSubmitting stuck true可能已有人在做 @henricop 于 14 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)可能已有人在做 @twotnguyen 于 14 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`可能已有人在做 @fenet-as 于 40 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Async validator doesn't re-trigger `isValidating` after first failed validation可能已有人在做 @drewsephski 于 44 天前认领。 未关闭
难度 2/5 1-2 天 新手友好度 72/100
维护者通常 1 天内回复
相似的 Issue
-
kind:defect
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
mux-labs/mux-frontend#1240 ·
维护者通常 1 天内回复
-
area: agents-mcp priority: normal
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
Wait for the IDS correction dialog to settle in the stale-audit test可能已有人在做 @louistrue 今天认领。 未关闭ready
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Hono path parameters with a regex pattern keep the pattern in the OpenAPI path可能已有人在做 @0z5a 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
cloudflare/chanfana#400 ·
维护者通常 1 天内回复