Newly pushed array fields do not show form-level errors on submit while existing errors remain
Maintainer thường phản hồi trong vòng 1 ngày
@nikhilsdabhade đang làm issue này rồi.
Từ ngày 4/6/2026.
Đá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
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu trong packages/form-core/src/FieldApi.ts, tập trung vào FieldApi.validateSync và vòng lặp validation khi không có validator ở cấp field. Tái hiện chuỗi submit, add-person, submit từ issue và sử dụng test case bị lỗi được cung cấp để xác minh rằng các lỗi ở cấp form đến được field mới; hoàn tất khi field array mới hiển thị lỗi required sau lần submit thứ hai.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When using a form-level validator, if the form already has an error and a new array field is added with pushValue, submitting again does not show the new field’s error even though it is invalid.
This happens both with and without canSubmitWhenInvalid. Although, for different reasons I think.
This reproduces with the same submit-driven sequence when the form-level validator is configured as onSubmit and also with e.g. onChange or onBlur.
With onChange/onBlur the missing error will appear when a change/blur happens anywhere in the form.
Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-e4ageewt?file=src%2FApp.tsx
Steps to reproduce
- Submit empty form.
- Click Add person.
- Submit again.
- The new person field does not show Name is required.
Expected behavior
After the second submit, all invalid fields should show errors, including the newly added array field.
How often does this bug happen?
Every time
Screenshots or Videos
https://github.com/user-attachments/assets/f667411d-2f92-4b3d-b37f-cb6191288957
Platform
- OS: Linux
- Browser: Chrome, Firefox
- Version: latest
TanStack Form adapter
react-form
TanStack Form version
1.29.0
TypeScript version
6.0.2
Additional context
Possible cause: for a newly mounted array field with no field-level validator for the active cause, FieldApi.validateSync(cause, errorFromForm) gets an empty validator array. Because the per-field validation loop never runs, the field never reconciles errorFromForm into meta.errorMap. So the form-level validator can report the error, but the new field does not pick it up until some later validation event causes that field state to reconcile.
Here is a small failing test case:
it('should apply form-level submit errors even when the field has no field-level submit validators', () => {
const form = new FormApi({
defaultValues: {
name: '',
},
})
form.mount()
const field = new FieldApi({
form,
name: 'name',
defaultMeta: {
isTouched: true,
},
})
field.mount()
field.validateSync('submit', {
onSubmit: 'Name is required',
})
expect(field.getMeta().errorMap.onSubmit).toBe('Name is required')
expect(field.getMeta().errors).toContain('Name is required')
})
Small hack to make it work as expected:
diff --git a/packages/form-core/src/FieldApi.ts b/packages/form-core/src/FieldApi.ts
--- a/packages/form-core/src/FieldApi.ts
+++ b/packages/form-core/src/FieldApi.ts
@@ -1679,6 +1679,10 @@ export class FieldApi<
validationLogic:
this.form.options.validationLogic || defaultValidationLogic,
})
+
+ const validatesToRun = validates.length
+ ? validates
+ : ([{ cause, validate: undefined }] as typeof validates)
const linkedFields = this.getLinkedFields(cause)
const linkedFieldValidates = linkedFields.reduce(
@@ -1752,7 +1756,7 @@ export class FieldApi<
}
}
- for (const validateObj of validates) {
+ for (const validateObj of validatesToRun) {
validateFieldFn(this, validateObj)
}
for (const fieldValitateObj of linkedFieldValidates) {
With canSubmitWhenInvalid: false I'm guessing it happens due to canSubmit blocking? Maybe that is intended? I think I would still expect validation to run.
- Ngôn ngữ chính
- TypeScript
- Star
- 6.8k
- Fork
- 705
- Merge trung bình
- 1 ngày 7 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 20 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 25 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 59 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 78 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 68/100
JuliusBrussee/caveman#1449 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
linagora/twake-calendar-frontend#1924 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: Class TV ModaĐang mởcheck:passed streams:add
Độ khó 1/5 Dưới một 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
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
libnativeapi/nativeapi#21 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
GiganticMinecraft/seichi-playguide#183 ·
Maintainer thường phản hồi trong vòng 1 ngày