Skip to content
PlaygroundForm Builder

Remote functions

Pick the package that matches your project’s @sveltejs/kit major version. sv add @sjsf does this for you.

Terminal window
npm i @sjsf/sveltekit3

Required peer dependencies: @sjsf/form@3.5.0 @sveltejs/kit@3.0.0 svelte@5.57.1

<script lang="ts">
import { BasicForm, createForm } from "@sjsf/form";
import { connect } from "@sjsf/sveltekit3/rf/client";
import type { Model } from "#lib/post.js";
import * as defaults from "#lib/sjsf/remote-defaults.js";
import { createPost, getInitialData } from "./data.remote.js";
const initialData = await getInitialData();
// `connect()` takes care of the `/{formId}` suffix that Kit v3 requires on
// every field name
const form = createForm(
await connect<Model>(createPost, {
...defaults,
...initialData,
})
);
</script>
<BasicForm {form} novalidate />

By default, enhanced submissions send the form’s own controls — the same parts a native submission would send — so the server parses both identically. No JSON serialization of the form value is involved.

Pass useJsonChunks to connect() to submit the form data as JSON. This needs JavaScript: without it the browser submits the fields on its own, so the submission may look different from the JSON one.

Fields whose schema declares no type are rejected unless the validator is given a convertUnknownEntry to handle them:

import type { FieldValue } from "@sjsf/form";
const validator = createServerValidator({
...defaults,
schema,
convertUnknownEntry: ({ value }) => value as FieldValue,
});
  • experimental.async does not apply to dependency code - issue.

    Add this to your vite.config.js

    optimizeDeps: {
    exclude: ['@sjsf/form', '@sjsf/sveltekit3/rf/client'],
    }
  • The form.value type on the client side is unknown because the RemoteForm type does not include information about the validator’s output type. Specify the type via connect generic: createForm(await connect<FormValue>(...)).