Skip to content
Playground Form Builder

Remote functions

Terminal window
npm i @sjsf/sveltekit@next
<script lang="ts">
import { tick } from "svelte";
import { BasicForm, createForm } from "@sjsf/form";
// WARN: You must export this ID Builder in your `defaults` file
import { createFormIdBuilder } from "@sjsf/sveltekit/rf";
import { connect } from "@sjsf/sveltekit/rf/client";
import * as defaults from "$lib/form-defaults";
import { createPost, getInitialData } from "./data.remote";
const initialData = await getInitialData();
const form = createForm(
await connect(
createPost.enhance(async ({ submit }) => {
await submit();
if (createPost.fields.allIssues()) {
return;
}
console.log(createPost.result);
// Waiting for an update from remote function
await tick();
form.reset();
}),
{
...defaults,
...initialData,
idBuilder: createFormIdBuilder,
// Required due to the use of `enhance`
fields: createPost.fields,
}
)
);
</script>
<BasicForm {form} novalidate />
  • experimental.async does not apply to dependency code - issue.

    Add this to your vite.config.js

    optimizeDeps: {
    exclude: ['@sjsf/form', '@sjsf/sveltekit/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. For now, you need to specify the type manually: createForm<FormValue>(...).