Should I preventDefault with Next.js server actions?
I am using Next server actions, but I want to include client side validation that prevents submit if there are any errors. If I include e.preventDefault, nothing happens. If I exclude e.preventDefault, the post is always sent. When I try to type into the input again, it does not change the value until 2 characters are entered.
How do I prevent submit on validation errors? How do I get input to trigger the change event after an invalid submit attempt?
Example here: https://stackblitz.com/edit/nextjs-dbp2u3qq?file=app%2Fexample-form.tsx
0 Replies