Newly pushed array fields do not show form-level errors on submit while existing errors remain
I maintainer di solito rispondono entro 1 giorno
@nikhilsdabhade ci sta già lavorando.
Dal 4/6/2026.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- react, typescript
- Ambito
- frontend
Direzione di ricerca
Inizia da packages/form-core/src/FieldApi.ts, concentrandoti su FieldApi.validateSync e sul ciclo di validazione quando non esistono validatori a livello di campo. Riproduci la sequenza submit, add-person, submit dell’issue e usa il test case fallito fornito per verificare che gli errori a livello di form raggiungano il nuovo campo; il lavoro è completo quando il nuovo campo array mostra il proprio errore required dopo il secondo submit.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 6.8k
- Fork
- 705
- Merge medio
- 1g 12h
- PR unite (30g)
- 14
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/form
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Forse già presa @fenet-as l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
TanStack/form#2427 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Async validator doesn't re-trigger `isValidating` after first failed validationForse già presa @drewsephski l’ha presa 26 giorni fa. Aperta
Difficoltà 2/5 1-2 giorni Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[v2 alpha] devtools are always light modeForse già presa @dikshit-n l’ha presa 60 giorni fa. Apertaarea: runtime scope: devtools type: bug v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
FormGroupApi.getRelatedFields and FieldApi.validate() use unguarded startsWith for group membership, matching unrelated fields with a shared name prefixForse già presa @HDPark95 l’ha presa 78 giorni fa. Apertaarea: runtime scope: core type: bug v1
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
TanStack/form#2337 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
FormApi: onSubmit/onServer error cleared on any non-matching validation cause, not just 'change'Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertav1 v2: needs investigation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/form
Issue simili
-
needs-area
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Azure/typespec-azure#5936 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 72/100
vercel-labs/scriptc#2910 ·
I maintainer di solito rispondono entro 1 giorno
-
automation missing-model model-sync provider:fireworks-ai
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
anomalyco/models.dev#12458 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno