`onSubmitInvalid` not called when `canSubmit` is false (v1.27.7)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
- #1997 de @Dhavanesh24cs412 — cerrado sin fusionar
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- react, typescript
- Área
- frontend
Línea de trabajo
Comienza en FormApi.js, cerca de la comprobación de handleSubmit en la línea 462, comparando el valor interno state.canSubmit con el valor form.state.canSubmit que muestra el ejemplo de React. Reproduce el caso de valor predeterminado no válido y verifica que invocar handleSubmit llame a onSubmitInvalid cuando canSubmit e isValid sean false.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- 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 26 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 60 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 79 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
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
unocss/unocss#5421 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
needs-area
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Azure/typespec-azure#5936 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 72/100
vercel-labs/scriptc#2910 ·
Los mantenedores suelen responder en 1 día
-
automation missing-model model-sync provider:fireworks-ai
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
anomalyco/models.dev#12458 ·
Los mantenedores suelen responder en 1 día