Skip to content

Commit 7efa2d0

Browse files
committed
Fixed client-side validation when taint option is false.
1 parent 17a7aeb commit 7efa2d0

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- When cancelling a request, timers were cancelled too early in [SPA mode](https://superforms.rocks/concepts/spa) and when [client-side validation](https://superforms.rocks/concepts/client-validation) failed.
1717
- [Proxies](https://superforms.rocks/concepts/proxy-objects) didn't set or update a nested path unless it previously existed.
18+
- The when the [taint option](https://superforms.rocks/concepts/tainted#tainted-store) was set to `false`, client-side validation was prevented.
1819

1920
## [1.10.2] - 2023-11-14
2021

src/lib/client/index.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,6 @@ export function superForm<
695695
compareAgainst: unknown,
696696
taintOptions: TaintOption<UnwrappedT>
697697
) {
698-
if (taintOptions === false) {
699-
return;
700-
} else if (taintOptions === 'untaint-all') {
701-
Tainted.set(undefined);
702-
return;
703-
}
704-
705698
let paths = comparePaths(newObj, compareAgainst);
706699

707700
if (typeof taintOptions === 'object') {
@@ -715,17 +708,19 @@ export function superForm<
715708
taintOptions = true;
716709
}
717710

718-
if (taintOptions === true) {
719-
LastChanges.set(paths);
720-
}
711+
LastChanges.set(paths);
721712

722713
if (paths.length) {
723-
Tainted.update((tainted) => {
724-
//console.log('Update tainted:', paths, newObj, compareAgainst);
725-
if (!tainted) tainted = {};
726-
setPaths(tainted, paths, taintOptions === true ? true : undefined);
727-
return tainted;
728-
});
714+
if (taintOptions === 'untaint-all') {
715+
Tainted.set(undefined);
716+
} else {
717+
Tainted.update((tainted) => {
718+
//console.log('Update tainted:', paths, newObj, compareAgainst);
719+
if (!tainted) tainted = {};
720+
setPaths(tainted, paths, taintOptions === true ? true : undefined);
721+
return tainted;
722+
});
723+
}
729724

730725
if (
731726
!(

src/routes/tests/array-component/+page.svelte

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@
33
import type { PageData } from './$types';
44
import SuperDebug from '$lib/client/SuperDebug.svelte';
55
import AutoComplete from './AutoComplete.svelte';
6+
import { schema } from './schema';
67
78
export let data: PageData;
89
910
const pageForm = superForm(data.form, {
10-
dataType: 'json'
11-
//validators: schema
11+
dataType: 'json',
12+
validators: schema
1213
});
1314
const { form, errors, message, enhance, tainted } = pageForm;
1415
1516
const options = [
1617
{ value: 'A', label: 'Aldebaran' },
1718
{ value: 'B', label: 'Betelgeuse' }
1819
];
19-
20-
const { fieldErrors } = arrayProxy(pageForm, 'sub.tags');
2120
</script>
2221

23-
<SuperDebug data={{ $form, $errors, $fieldErrors }} />
24-
25-
{#if $tainted}<h3>FORM IS TAINTED</h3>{/if}
22+
{#if $tainted?.sub?.tags?.[0]}<h3>FORM IS TAINTED</h3>{/if}
2623

2724
{#if $message}<h4>{$message}</h4>{/if}
2825

@@ -33,6 +30,8 @@
3330
</div>
3431
</form>
3532

33+
<SuperDebug data={{ $form, $errors, $tainted }} />
34+
3635
<style lang="scss">
3736
form {
3837
margin: 2rem 0;

0 commit comments

Comments
 (0)