Event order - ciscoheat/sveltekit-superforms GitHub Wiki

Superforms event flowchart

Event API

onSubmit: ({ action, data, form, controller, cancel }) => void;

onSubmit hooks you in to SvelteKit's use:enhance function. See SvelteKit docs for the SubmitFunction signature.

onResult: ({ result, formEl, cancel }) => void

When you want detailed control, onResult gives you the ActionResult in result. You can modify it, which will be used further down the event chain.

formEl is the HTMLFormElement of the form.

cancel() is a function which will cancel the rest of the event chain and any form updates.

onUpdate: ({ form, cancel }) => void

If you don't care about the specifics of the ActionResult, onUpdate, lets you enter just before the form update is being applied and gives you the option to modify the validation result in form, or cancel() the update altogether.

onUpdated: ({ form }) => void

If you just want the default behaviour and act on the validation success or its data, onUpdated is the simplest way. form is the validation result, and should be considered read-only here.

onError: (({ result, message }) => void) | 'apply'

onError allows you to act on ActionResult errors. You can use the message store parameter to set it to the error value here.

By setting onError to apply, the default applyAction behaviour will be used, effectively rendering the nearest +error boundary (and wiping out the form, so be careful).