Skip to content

Commit 865251b

Browse files
committed
Client-side validation now works for SPA and novalidate.
Fixes #297.
1 parent 9de83ee commit 865251b

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Tainted fields were set to undefined when not needed, unnecessarily triggering client-side validation.
13-
- Schema transformations weren't updating the form data on the client. ([#298](https://github.com/ciscoheat/sveltekit-superforms/issues/298))
13+
- Schema transformations now updates the form data on the client depending on input type. Checkboxes, radio buttons and selects updates the data immediately. Other inputs waits until blurred. ([#298](https://github.com/ciscoheat/sveltekit-superforms/issues/298))
14+
- If in [SPA mode](https://superforms.rocks/concepts/spa), the `novalidate` attribute now only disables the browser validation constraints, not the entire client-side validation.
1415

1516
## [1.11.0] - 2023-11-28
1617

src/lib/client/formEnhance.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,15 @@ export function formEnhance<T extends AnyZodObject, M>(
304304
if (options.flashMessage) cancelFlash(options);
305305
} else {
306306
// Client validation
307-
const validation = await clientValidation(
308-
formEl.noValidate ||
307+
const noValidate =
308+
!options.SPA &&
309+
(formEl.noValidate ||
309310
((submit.submitter instanceof HTMLButtonElement ||
310311
submit.submitter instanceof HTMLInputElement) &&
311-
submit.submitter.formNoValidate)
312-
? undefined
313-
: options.validators,
312+
submit.submitter.formNoValidate));
313+
314+
const validation = await clientValidation(
315+
noValidate ? undefined : options.validators,
314316
get(data),
315317
get(formId),
316318
get(constraints),

src/routes/tests/spa-schema-transform/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
<p>{customCheck}</p>
4545

46-
<form method="POST" use:enhance>
46+
<form method="POST" novalidate use:enhance>
4747
<label>
4848
Name<br />
4949
<input

0 commit comments

Comments
 (0)