Next.js Discord

Discord Forum

how to prevent a `Form` from reloading the page when using the action attribute.

Unanswered
Field Sparrow posted this in #help-forum
Open in Discord
Avatar
Field SparrowOP
i could do everything in on Submit but next Form has the required action attribute.

8 Replies

Avatar
next 15 right @Field Sparrow
Avatar
Field SparrowOP
yep
Avatar
Field SparrowOP
can you tell me why they made the action attriubte compulsory in next forms
Avatar
Field SparrowOP
i can't get a response from the server action back
i would rather just use an onSubmit
Avatar
African Slender-snouted Crocodile
It looks here https://nextjs.org/docs/app/api-reference/components/form like a combination of action="" (empty string) and setting preventDefault in the onSubmit handler might do what you want?
The empty string doesn't make it do nothing, but it might be the simplest thing to set it as if you have no intention of using that behaviour