Skip to content

Commit

Permalink
feat: report submission on submit (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung authored Apr 1, 2024
1 parent ddbbcc4 commit 5aff42c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 7 additions & 2 deletions packages/conform-dom/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,13 @@ export function createFormContext<
submitter,
});

if (submission.status !== 'success' && submission.error !== null) {
report(submission.reply());
if (submission.status === 'success' || submission.error !== null) {
const result = submission.reply();

report({
...result,
status: result.status !== 'success' ? result.status : undefined,
});
}

return { ...result, submission };
Expand Down
13 changes: 8 additions & 5 deletions packages/conform-react/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getPaths,
isPrefix,
STATE,
INTENT,
} from '@conform-to/dom';
import {
type FormEvent,
Expand Down Expand Up @@ -466,13 +467,15 @@ export function createFormContext<
const result = context.submit(submitEvent);

if (
result.submission &&
result.submission.status !== 'success' &&
result.submission.error !== null
!result.submission ||
result.submission.status === 'success' ||
result.submission.error === null
) {
event.preventDefault();
if (!result.formData.has(INTENT)) {
onSubmit?.(event, result);
}
} else {
onSubmit?.(event, result);
event.preventDefault();
}
},
onUpdate(options) {
Expand Down

0 comments on commit 5aff42c

Please sign in to comment.