You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Without `use:enhance`, an id can be specified in the options or in a hidden form field called `__superform_id`.
34
+
If you're having multiple forms without `use:enhance`, an id can be specified in the options, or in a hidden form field called `__superform_id`.
24
35
25
36
For extra safety, a warning will be emitted if identical id's are detected.
26
37
@@ -39,7 +50,7 @@ This was previously an undocumented function called `defaultData`. If you've use
39
50
40
51
### superValidateSync
41
52
42
-
When using `superValidate` on the client, you previously had to use a `+page.ts` file to call `superValidate`, since it is asynchronous. But now you can import `superValidateSync` and use it in components directly. Can be very convenient in SPA:s.
53
+
When using `superValidate` on the client, you previously had to use a `+page.ts` file to call `superValidate`, since it is asynchronous. But now you can import `superValidateSync` and use it in components directly (which assumes that there is no async validation in the schema). Can be very convenient in SPA:s.
43
54
44
55
```svelte
45
56
<script lang="ts">
@@ -53,7 +64,7 @@ When using `superValidate` on the client, you previously had to use a `+page.ts`
53
64
54
65
### String path accessors
55
66
56
-
When you wanted to set errors, use proxies and nested data in components, the array syntax was a bit clunky. It has now been replaced with a typesafe string path, so you can write it just as you would access an object property:
67
+
When you wanted to set errors, use proxies and have nested data in components, the array syntax was a bit clunky. It has now been replaced with a typesafe string path, so you can write it just as you would access an object property:
57
68
58
69
```diff
59
70
import { setError } from 'sveltekit-superforms/server'
The above will be available on the client as `$errors._errors` as before, and will be removed (or added) upon client-side validation.
105
+
The above error set in `refine` will be available on the client as `$errors._errors` as before, and will be removed (or added) during client-side validation.
106
+
107
+
If you'd like the error to persist, `message` will persist until the next form submission.
95
108
96
109
```ts
97
110
const form =awaitsuperValidate(request, schema);
@@ -102,35 +115,70 @@ if (form.data.password != form.data.confirmPassword)
- validate(['tags', i, 'name'], { update: false });
126
+
+ validate(`tags[${i}].name`, { update: false });
114
127
```
115
128
116
-
This also applies to generic components, so you should change the type of the field prop, as described on the componentization page:
129
+
This also applies to generic components, so you should change the type of the field prop, as described on the [componentization page](https://superforms.vercel.app/components):
117
130
118
131
```svelte
119
132
<script lang="ts">
120
133
import type { z, AnyZodObject } from 'zod';
121
-
import type { UnwrapEffects } from 'sveltekit-superforms';
122
-
import type { SuperForm, StringPath } from 'sveltekit-superforms/client';
123
-
import { formFieldProxy } from 'sveltekit-superforms/client';
134
+
import type { ZodValidation, StringPathLeaves } from '$lib';
135
+
import { formFieldProxy, type SuperForm } from '$lib/client';
124
136
125
137
type T = $$Generic<AnyZodObject>;
126
138
127
-
export let form: SuperForm<UnwrapEffects<T>, unknown>;
128
-
export let field: string & StringPath<z.infer<UnwrapEffects<T>>>;
139
+
export let form: SuperForm<ZodValidation<T>, unknown>;
140
+
export let field: string & StringPathLeaves<z.infer<T>>;
This only applies to `formFieldProxy` because it maps to errors and constraints as well as the form. If you want to proxy a form value only, the `fieldProxy` will work with any of the above.
The signature for `allErrors` and `firstError` has changed, to make it easier to group related messages:
@@ -140,21 +188,38 @@ The signature for `allErrors` and `firstError` has changed, to make it easier to
140
188
+ { path: string; messages: string[] }
141
189
```
142
190
143
-
The path follows the same format as the string accessor path above.
191
+
The path follows the same format as the above described string accessor path. If you want to display all messages grouped:
144
192
145
193
```svelte
146
194
{#if $allErrors.length}
147
195
<ul>
148
196
{#each $allErrors as error}
149
197
<li>
150
198
<b>{error.path}:</b>
151
-
{error.messages}
199
+
{error.messages.join('. ')}.
152
200
</li>
153
201
{/each}
154
202
</ul>
155
203
{/if}
156
204
```
157
205
206
+
Or as before, separate for each error:
207
+
208
+
```svelte
209
+
{#if $allErrors.length}
210
+
<ul>
211
+
{#each $allErrors as error}
212
+
{#each error.messages as message}
213
+
<li>
214
+
<b>{error.path}:</b>
215
+
{message}.
216
+
</li>
217
+
{/each}
218
+
{/each}
219
+
</ul>
220
+
{/if}
221
+
```
222
+
158
223
## defaultData
159
224
160
225
The `defaultData` function is now called `defaultValues`.
@@ -204,4 +269,13 @@ The following `superValidate` options have changed:
204
269
const form =awaitsuperValidate(schema, { errors: true });
205
270
```
206
271
207
-
The [changelog](https://github.com/ciscoheat/sveltekit-superforms/blob/main/CHANGELOG.md) has a full list of changes that aren't breaking. So please try this release candidate, and let me know in a [Github issue](https://github.com/ciscoheat/sveltekit-superforms/issues) or on [Discord](https://discord.gg/AptebvVuhB) if you find some problem. Thank you for helping out towards 1.0!
272
+
# Try it out!
273
+
274
+
To install this RC, update `package.json` with the new version, then update:
275
+
276
+
```diff
277
+
- "sveltekit-superforms": "^0.8.7",
278
+
+ "sveltekit-superforms": "^1.0.0-rc.1",
279
+
```
280
+
281
+
The [changelog](https://github.com/ciscoheat/sveltekit-superforms/blob/main/CHANGELOG.md) has a full list of changes. So please try this release candidate, and let me know in a [Github issue](https://github.com/ciscoheat/sveltekit-superforms/issues) or on [Discord](https://discord.gg/AptebvVuhB) if you find some problem. Thank you for helping out towards 1.0!
0 commit comments