useSubmit function not calling Action upon form submission #7748
-
Hello All I am really struggling on why this is not working. I am attempting a simple form submission which should kick off the Action function to input data into an external database (GCP Firestore). export const action = async ({ request }) => {
const form = await request.formData();
const searchTerms = form.get("search");
const exclusionTerms = form.get("exclusion");
//put into firestore
...
return json({
message: "Saved"
});
};
export default function Index() {
...
const loadData = useLoaderData();
const actionData = useActionData<typeof action>();
const submit = useSubmit();
...
const handleSubmit = () => submit({
search: search,
exclusion: exclusion
},
{ method: "POST" });
return (
<Form method="POST" onSubmit={handleSubmit}>
<FormLayout>
<TextField
value={search}
label="Search Terms. Use AND/OR as needed"
type="text"
name="search"
onChange={handleSearchChange}
/>
<TextField
value={exclusion}
label="Exclusion Terms"
type="text"
name="exclusion"
onChange={handleExclusionChange}
}
/>
</FormLayout>
<Button variant="primary" loading={isLoading} >Save</Button>
{actionData ? actionData.message : null}
</Form>
) From what I understand, the Any insights would be really appreciate. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
ok somehow after a couple hours of struggling, stepping away to do school pickup, and returned to find that the problem is attaching |
Beta Was this translation helpful? Give feedback.
ok somehow after a couple hours of struggling, stepping away to do school pickup, and returned to find that the problem is attaching
onSubmit
to Form. Everything is working as expected when instead callinghandleSubmit
by usingonClick
on the Button.