Skip to content

Commit 6ffa729

Browse files
authored
Fix/submit after error (#641)
* fix(useOmegaForm): clear field onSubmit errors after failed submission * bump
1 parent 3a38c26 commit 6ffa729

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

.changeset/sparkly-cars-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect-app/vue-components": patch
3+
---
4+
5+
Fixes useOmegaFormErrorStale stale errorMap

packages/vue-components/src/components/OmegaForm/useOmegaForm.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,24 @@ export const useOmegaForm = <
979979
}
980980
})
981981

982+
// Clear all field onSubmit errors when any value changes after a failed submission.
983+
// Form-level onSubmit validation (e.g. union schemas) distributes errors to individual fields.
984+
// TanStack only clears the changed field's onSubmit error, leaving sibling fields with stale
985+
// errors that keep isFieldsValid=false and block re-submission.
986+
const lastSubmitAttempts = ref(0)
987+
const submissionAttempts = form.useStore((s) => s.submissionAttempts)
988+
const formValues = form.useStore((s) => s.values)
989+
watch(formValues, () => {
990+
if (lastSubmitAttempts.value === submissionAttempts.value) return
991+
lastSubmitAttempts.value = submissionAttempts.value
992+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
993+
for (const info of Object.values(form.fieldInfo) as any[]) {
994+
if (info?.instance?.state.meta.errorMap?.onSubmit) {
995+
info.instance.setMeta((prev: any) => ({ ...prev, errorMap: { ...prev.errorMap, onSubmit: undefined } }))
996+
}
997+
}
998+
}, { deep: true })
999+
9821000
const errorContext = { form: formWithExtras, fieldMap }
9831001

9841002
return Object.assign(formWithExtras, {

0 commit comments

Comments
 (0)