`onSubmitInvalid` not called when `canSubmit` is false (v1.27.7)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #1997 của @Dhavanesh24cs412 — đã đóng, không merge
Đá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
Hướng nghiên cứu
Bắt đầu trong FormApi.js, tại phần kiểm tra handleSubmit gần dòng 462, bằng cách so sánh giá trị state.canSubmit nội bộ với giá trị form.state.canSubmit được hiển thị bởi ví dụ React. Tái hiện trường hợp giá trị mặc định không hợp lệ và xác minh rằng việc gọi handleSubmit sẽ gọi onSubmitInvalid khi canSubmit và isValid là false.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
onSubmitInvalid callback is not being called when the form is invalid and handleSubmit() is invoked, even though canSubmit is false and isValid is false.
This appears to be the same issue as #1696, which was supposedly fixed in PR #1697 (merged September 30, 2025). However, the issue persists in v1.27.7.
Your minimal, reproducible example
import { useForm } from '@tanstack/react-form'
import { zodValidator } from '@tanstack/zod-form-adapter'
import { z } from 'zod'
const schema = z.object({
value: z.number().min(1, 'Value must be greater than 0'),
})
function MyForm() {
const form = useForm({
validatorAdapter: zodValidator(),
defaultValues: { value: 0 },
validators: {
onChange: schema,
onSubmit: schema,
},
onSubmitInvalid: () => {
console.log('onSubmitInvalid called') // This is NEVER called
},
onSubmit: ({ value }) => {
console.log('onSubmit called', value)
},
})
return (
<button
onClick={() => {
console.log('Before handleSubmit:', {
canSubmit: form.state.canSubmit,
isValid: form.state.isValid,
submissionAttempts: form.state.submissionAttempts,
})
form.handleSubmit()
console.log('After handleSubmit:', {
canSubmit: form.state.canSubmit,
isValid: form.state.isValid,
submissionAttempts: form.state.submissionAttempts,
})
}}
>
Submit
</button>
)
}
Steps to reproduce
- Create a form with
onChangeandonSubmitvalidators - Set default values that are invalid (e.g.,
value: 0when validator requiresmin(1)) - Define
onSubmitInvalidcallback - Click the submit button
- Observe that
onSubmitInvalidis never called
Expected behavior
onSubmitInvalid should be called when:
canSubmitisfalseisValidisfalsehandleSubmit()is invoked
How often does this bug happen?
Every time
Screenshots or Videos
Platform
- OS: macOS
- Browser: Chrome
- TanStack Form version: 1.27.7
- TypeScript version: 5.x
TanStack Form adapter
None
TanStack Form version
1.27.7
TypeScript version
5.2.2
Additional context
Looking at the source code in FormApi.js, the check at line ~462 should call onSubmitInvalid:
if (!this.state.canSubmit && !this._devtoolsSubmissionOverride) {
this.options.onSubmitInvalid?.({
value: this.state.values,
formApi: this,
meta: submitMetaArg
});
return;
}
However, it seems like this.state.canSubmit might be reading a stale or different value than what's visible from form.state.canSubmit in React, possibly due to the derived store not being synchronized at the time of the check.
- Ngôn ngữ chính
- TypeScript
- Star
- 6.8k
- Fork
- 705
- Merge trung bình
- 1 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 14
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/form
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Có thể đã có người làm @fenet-as đã nhận 22 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
TanStack/form#2427 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Async validator doesn't re-trigger `isValidating` after first failed validationCó thể đã có người làm @drewsephski đã nhận 27 ngày trước. Đang mở
Độ khó 2/5 1-2 ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[v2 alpha] devtools are always light modeCó thể đã có người làm @dikshit-n đã nhận 61 ngày trước. Đang mởarea: runtime scope: devtools type: bug v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
FormGroupApi.getRelatedFields and FieldApi.validate() use unguarded startsWith for group membership, matching unrelated fields with a shared name prefixCó thể đã có người làm @HDPark95 đã nhận 79 ngày trước. Đang mởarea: runtime scope: core type: bug v1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
TanStack/form#2337 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
FormApi: onSubmit/onServer error cleared on any non-matching validation cause, not just 'change'Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởv1 v2: needs investigation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/form
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
caprover/caprover-frontend#273 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ai-driven-dev/framework#1147 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent-ui bug p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
cybersemics/em#6232 ·
Maintainer thường phản hồi trong vòng 1 ngày