fix(form-core): Resolve onSubmitInvalid not being called with invalid default values#1997
Conversation
…ck#1990) - Remove stale canSubmit check that prevented onSubmitInvalid from being called - On first render, canSubmit was true even with invalid default values - Proper validation checks after this point correctly handle onSubmitInvalid - Fixes: onSubmitInvalid not called when form is invalid with default values
|
|
This solution effectively addresses the issue where |
|
In what way is |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --targets=test:sherif,test:knip,tes... |
❌ Failed | 2m 14s | View ↗ |
nx run-many --target=build --exclude=examples/** |
✅ Succeeded | 33s | View ↗ |
☁️ Nx Cloud last updated this comment at 2026-01-18 08:51:50 UTC
|
I would solve this issue by tonight! The 9 lines of code i deleted in my branch executed well once a run, i would double check and cinfigure the changes |

Problem
When a form is initialized with invalid default values, the
onSubmitInvalidcallback was not being called on the first submission attempt. This occurred because an earlycanSubmitcheck in the_handleSubmitmethod would short-circuit the validation flow before reaching the proper validation logic.Root Cause
The issue was located in
packages/form-core/src/FormApi.tsin the_handleSubmitmethod. An early check:This check was preventing the form from:
validateAllFields('submit')to validate all fieldsonSubmitInvalidcallback when validation failsSolution
Removed the stale early
canSubmitcheck from the_handleSubmitmethod. The form now:validateAllFields('submit')onSubmitInvalidwhen validation failsChanges Made
canSubmitguard in_handleSubmitmethodonSubmitInvalidcallback is invoked when appropriateTesting
This fix addresses the issue described in #1990 where forms with invalid default values were not triggering the
onSubmitInvalidcallback.Closes #1990- Fixes: onSubmitInvalid not called when form is invalid with default values
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact