Skip to content

Commit

Permalink
Get submit action string when submitting via JS
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnaab committed Oct 29, 2024
1 parent 84927c0 commit 1dbf371
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ const AppFormRoute = () => {
uswdsRoot: ctx.uswdsRoot,
}}
session={formSessionResponse.formSession}
onSubmit={data => actions.onSubmitForm({ formId: id, data })}
onSubmit={data => {
actions.onSubmitForm({ formId: id, data });
}}
/>
)}
</>
Expand Down
16 changes: 14 additions & 2 deletions packages/design/src/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,22 @@ export default function Form({
className="usa-form margin-bottom-3 maxw-full"
onSubmit={
onSubmit
? formMethods.handleSubmit(async data => {
? formMethods.handleSubmit(async (data, event) => {
const submitEvent = event?.nativeEvent as
| SubmitEvent
| undefined;
if (submitEvent === undefined) {
console.error(
"Can't handle submission without event"
);
return;
}
const action = (
submitEvent.submitter as HTMLButtonElement
)?.value;
updatePrompt(data);
console.log('Submitting form...');
onSubmit(data);
onSubmit({ ...data, action });
})
: undefined
}
Expand Down

0 comments on commit 1dbf371

Please sign in to comment.