Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(form-core): add canSubmitWhenInvalid form option #1234

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

matthiasschwarz
Copy link

Allows to submit a form when invalid with the new canSubmitWhenInvalid form option.

Resolves #1109.

@harry-whorlow
Copy link
Contributor

Out of curiosity, is there a reason for the two tests? onMount and onChange?

Copy link

nx-cloud bot commented Mar 17, 2025

View your CI Pipeline Execution ↗ for commit 6975e8c.

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

☁️ Nx Cloud last updated this comment at 2025-03-17 09:56:42 UTC

Comment on lines +948 to +951
(!hasOnMountError || this.options.canSubmitWhenInvalid)) ||
(!isValidating &&
!currBaseStore.isSubmitting &&
(isValid || this.options.canSubmitWhenInvalid))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic dose not work, if you run pnpm test:lib you will get failing tests.

would something like this work?

const submitInvalid = this.options.canSubmitWhenInvalid ?? false
const canSubmit =
  (currBaseStore.submissionAttempts === 0 &&
    !isTouched &&
    (!hasOnMountError || submitInvalid)) ||
  (!isValidating &&
    !currBaseStore.isSubmitting &&
    (isValid || submitInvalid))

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.

Option to trigger onSubmitInvalid on every submit
2 participants