diff --git a/.changeset/hip-beers-listen.md b/.changeset/hip-beers-listen.md new file mode 100644 index 0000000..c2d4e4d --- /dev/null +++ b/.changeset/hip-beers-listen.md @@ -0,0 +1,5 @@ +--- +"simple-stack-form": patch +--- + +Fix accidental form submission on client validation errors diff --git a/examples/form/src/components/preact/Form.tsx b/examples/form/src/components/preact/Form.tsx index 788f2d6..5691635 100644 --- a/examples/form/src/components/preact/Form.tsx +++ b/examples/form/src/components/preact/Form.tsx @@ -76,6 +76,7 @@ export function Form({ return formContext.trackAstroSubmitStatus(); } + e.preventDefault(); e.stopPropagation(); formContext.setValidationErrors(parsed.fieldErrors); }} diff --git a/examples/form/src/components/react/Form.tsx b/examples/form/src/components/react/Form.tsx index 0a071d1..5c5e337 100644 --- a/examples/form/src/components/react/Form.tsx +++ b/examples/form/src/components/react/Form.tsx @@ -78,6 +78,7 @@ export function Form({ return formContext.trackAstroSubmitStatus(); } + e.preventDefault(); e.stopPropagation(); formContext.setValidationErrors(parsed.fieldErrors); }} diff --git a/packages/form/templates/preact/Form.tsx b/packages/form/templates/preact/Form.tsx index 821e1a3..50f3a49 100644 --- a/packages/form/templates/preact/Form.tsx +++ b/packages/form/templates/preact/Form.tsx @@ -74,6 +74,7 @@ export function Form({ return formContext.trackAstroSubmitStatus(); } + e.preventDefault(); e.stopPropagation(); formContext.setValidationErrors(parsed.fieldErrors); }} diff --git a/packages/form/templates/react/Form.tsx b/packages/form/templates/react/Form.tsx index 383844b..2aa8ced 100644 --- a/packages/form/templates/react/Form.tsx +++ b/packages/form/templates/react/Form.tsx @@ -78,6 +78,7 @@ export function Form({ return formContext.trackAstroSubmitStatus(); } + e.preventDefault(); e.stopPropagation(); formContext.setValidationErrors(parsed.fieldErrors); }}