Newly pushed array fields do not show form-level errors on submit while existing errors remain
Los mantenedores suelen responder en 1 día
@nikhilsdabhade ya está trabajando en esto.
Desde el 4/6/2026.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- react, typescript
- Área
- frontend
Línea de trabajo
Comienza en packages/form-core/src/FieldApi.ts, centrándote en FieldApi.validateSync y en el bucle de validación cuando no existen validadores a nivel de campo. Reproduce la secuencia submit, add-person, submit del issue y usa el caso de prueba fallido proporcionado para verificar que los errores a nivel de formulario llegan al nuevo campo; se considera terminado cuando el nuevo campo de tipo array muestra su error de requerido después del segundo submit.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 6.8k
- Forks
- 705
- Merge medio
- 1 d 12 h
- PR fusionados (30 d)
- 14
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/form
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Posiblemente ocupada @fenet-as la tomó hace 21 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
TanStack/form#2427 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Async validator doesn't re-trigger `isValidating` after first failed validationPosiblemente ocupada @drewsephski la tomó hace 25 días. Abierto
Dificultad 2/5 1-2 días Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[v2 alpha] devtools are always light modePosiblemente ocupada @dikshit-n la tomó hace 59 días. Abiertoarea: runtime scope: devtools type: bug v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
FormGroupApi.getRelatedFields and FieldApi.validate() use unguarded startsWith for group membership, matching unrelated fields with a shared name prefixPosiblemente ocupada @HDPark95 la tomó hace 78 días. Abiertoarea: runtime scope: core type: bug v1
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
TanStack/form#2337 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
FormApi: onSubmit/onServer error cleared on any non-matching validation cause, not just 'change'Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertov1 v2: needs investigation
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/form
Issues similares
-
Add API: BlockVectra Data APIAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
remotion-dev/remotion#12905 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
supermomonga/paseo-plugin-zcode-provider#83 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
oxidecomputer/skepsis#102 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
voidzero-dev/void#677 ·
Los mantenedores suelen responder en 1 día