sveltekit-superforms
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -17,3 +17,3 @@ import { type MaybePromise, type SubmitFunction } from '$app/forms'; | ||
* @param onUpdate Callback when the form is updated, by either a POST or a load function. | ||
* @param {boolean} applyAction If false, will not automatically update the form when $page updates. Useful for modal forms. In that case, use the onResult callback to update the form. | ||
* @param {boolean} applyAction If false, will not automatically update the form when $page updates. Useful for modal forms. | ||
*/ | ||
@@ -28,3 +28,3 @@ export type FormOptions<T extends AnyZodObject> = { | ||
stickyNavbar?: string; | ||
taintedMessage?: string | false; | ||
taintedMessage?: string | false | null; | ||
onSubmit?: (...params: Parameters<SubmitFunction>) => unknown | void; | ||
@@ -38,7 +38,7 @@ onResult?: (event: { | ||
onUpdate?: (event: { | ||
validation: Validation<T>; | ||
form: Validation<T>; | ||
cancel: () => void; | ||
}) => MaybePromise<unknown | void>; | ||
onUpdated?: (event: { | ||
validation: Validation<T>; | ||
form: Validation<T>; | ||
}) => MaybePromise<unknown | void>; | ||
@@ -45,0 +45,0 @@ onError?: ((result: Extract<ActionResult, { |
@@ -184,17 +184,17 @@ import { enhance, applyAction } from '$app/forms'; | ||
} | ||
function rebind(validation, untaint) { | ||
Validated.set(validation.validated); | ||
Errors.set(validation.errors); | ||
Data.set(validation.data); | ||
Empty.set(validation.empty); | ||
Message.set(validation.message); | ||
function rebind(form, untaint) { | ||
Validated.set(form.validated); | ||
Errors.set(form.errors); | ||
Data.set(form.data); | ||
Empty.set(form.empty); | ||
Message.set(form.message); | ||
if (untaint && options.taintedMessage) { | ||
savedForm = { ...validation.data }; | ||
savedForm = { ...form.data }; | ||
} | ||
} | ||
async function _update(validation, untaint) { | ||
async function _update(form, untaint) { | ||
if (options.onUpdate) { | ||
let cancelled = false; | ||
await options.onUpdate({ | ||
validation, | ||
form, | ||
cancel: () => (cancelled = true) | ||
@@ -205,10 +205,10 @@ }); | ||
} | ||
if (validation.validated && options.resetForm) { | ||
if (form.validated && options.resetForm) { | ||
_resetForm(); | ||
} | ||
else { | ||
rebind(validation, untaint); | ||
rebind(form, untaint); | ||
} | ||
if (options.onUpdated) { | ||
await options.onUpdated({ validation }); | ||
await options.onUpdated({ form }); | ||
} | ||
@@ -234,4 +234,4 @@ } | ||
} | ||
const validation = result.data.form ?? emptyForm(); | ||
_update(validation, untaint ?? (result.status >= 200 && result.status < 300)); | ||
const form = result.data.form ?? emptyForm(); | ||
_update(form, untaint ?? (result.status >= 200 && result.status < 300)); | ||
}; | ||
@@ -238,0 +238,0 @@ if (browser) { |
{ | ||
"name": "sveltekit-superforms", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"author": "Andreas Söderlund <ciscoheat@gmail.com> (https://blog.encodeart.dev)", | ||
@@ -5,0 +5,0 @@ "description": "Supercharge your SvelteKit forms with this powerhouse of a library!", |
@@ -17,3 +17,3 @@ # sveltekit-superforms 💥 | ||
- Proxy objects for handling data conversions to string and back again. | ||
- Provide feedback unlike anything else with auto-updating timers for long response times, based on [The 3 important limits](https://www.nngroup.com/articles/response-times-3-important-limits/). | ||
- Provide unparallelled feedback with auto-updating timers for long response times, based on [The 3 important limits](https://www.nngroup.com/articles/response-times-3-important-limits/). | ||
- Even more care for the user: No form data loss, by preventing error page rendering as default. | ||
@@ -232,3 +232,3 @@ - Hook into a number of events for full control over submitting, `ActionResult` and validation updates. | ||
```ts | ||
taintedMessage: string | false = '<A default message in english>' | ||
taintedMessage: string | null | false = '<A default message in english>' | ||
``` | ||
@@ -262,3 +262,3 @@ | ||
```ts | ||
onUpdated: ({ validation }) => void | ||
onUpdated: ({ form }) => void | ||
``` | ||
@@ -269,3 +269,3 @@ | ||
```ts | ||
onUpdate: ({ validation, cancel }) => void | ||
onUpdate: ({ form, cancel }) => void | ||
``` | ||
@@ -452,3 +452,3 @@ | ||
This journey can be quite easy to take with `sveltekit-superforms`. Let's see how it works by starting over with the default route: | ||
This journey can be quite easy to take with `sveltekit-superforms`. Let's see how it works by starting over with the default route. The [Zod validation schema reference](https://zod.dev/?id=primitives) can be useful as well. | ||
@@ -758,3 +758,3 @@ **src/routes/+page.server.ts** | ||
stickyNavbar?: string; | ||
taintedMessage?: string | false; | ||
taintedMessage?: string | null | false; | ||
timeoutMs?: number; | ||
@@ -776,3 +776,3 @@ validators?: Validators<T>; | ||
async onUpdate?: (event: { | ||
validation: Validation<T>; | ||
form: Validation<T>; | ||
cancel: () => void; | ||
@@ -782,3 +782,3 @@ }) | ||
async onUpdated?: (event: { | ||
validation: Validation<T>; | ||
form: Validation<T>; | ||
}) | ||
@@ -841,7 +841,7 @@ | ||
Used when returning default values from `superValidate` for an entity, or when converting `FormData`. | ||
Used when returning default values from `superValidate` for an entity, or when a `FormData` field is empty. | ||
| type | value | | ||
| --------------- | ----------- | | ||
| `string` | `''` | | ||
| `string` | `""` | | ||
| `number` | `0` | | ||
@@ -856,4 +856,4 @@ | `boolean` | `false` | | ||
The library is quite stable so don't expect any major changes, but there could still be minor breaking changes until version 1.0. | ||
The library is quite stable so don't expect any major changes, but there could still be minor breaking changes until version 1.0, mostly variable naming. | ||
Ideas, feedback, bug reports, PR:s, etc, are very welcome as a [github issue](https://github.com/ciscoheat/sveltekit-superforms/issues). |
77908