Skip to content

Conversation

jiji-hoon96
Copy link

Problem The onSubmitInvalid callback was not being called when canSubmit is false because the handleSubmit method returned early before running validation.

Solution

  • Modified handleSubmit logic to always run validation regardless of canSubmit state
  • Call onSubmitInvalid with updated validation state when canSubmit is false
  • Respect canSubmitWhenInvalid option behavior

Changes

  • Updated FormApi.handleSubmit() method in FormApi.ts
  • Added comprehensive test cases for onSubmitInvalid callback scenarios
  • Added tests for canSubmitWhenInvalid option interaction

#1697 #1696

Copy link

nx-cloud bot commented Aug 21, 2025

View your CI Pipeline Execution ↗ for commit 69f1464

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 12s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 20s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-21 14:29:38 UTC

@LeCarbonator
Copy link
Contributor

The problem is not that canSubmit causes an early return. The errors were caused by validation that has not yet been resolved, which means you have no reason to rerun validation on data that's already invalid.

The user has the option to bypass this using canSubmitWhenInvalid. However, the default behaviour is that canSubmit: false should not run validate('submit').

The unit tests could be useful for ensuring proper onSubmitInvalid behaviour, though. Would you mind adding them to #1697 ?

@jiji-hoon96
Copy link
Author

I understand.
Then I will close the PR and upload only the modified unit test to #1697.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants