Skip to content
Playground Form Builder

svelte-jsonschema-form

Svelte 5 library for creating forms based on JSON schema.

Install as a community add-on using the Svelte CLI.

Terminal window
npx sv add @sjsf
<script lang="ts">
import { createForm, BasicForm, getValueSnapshot } from "@sjsf/form";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../model";
import * as defaults from "./defaults";
const form = createForm<CreateUser>({
...defaults,
// required due to several forms on the page
idPrefix: "basic",
initialValue,
schema,
uiSchema,
onSubmit: ({ name }) => window.alert(`Hello, ${name}`),
});
</script>
<BasicForm {form} />
<pre>{JSON.stringify(getValueSnapshot(form), withFile, 2)}</pre>

<script lang="ts">
import { BasicForm, createForm, getValueSnapshot } from "@sjsf/form";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../model";
import * as defaults from "./defaults";
const form = createForm<CreateUser>({
...defaults,
// required due to several forms on the page
idPrefix: "daisyui5",
initialValue,
schema,
uiSchema,
onSubmit: ({ name }) => window.alert(`Hello, ${name}`),
});
</script>
<BasicForm {form} />
<pre>{JSON.stringify(getValueSnapshot(form), withFile, 2)}</pre>

<script lang="ts">
import { BasicForm, createForm, getValueSnapshot } from "@sjsf/form";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../model";
import * as defaults from "./defaults";
const form = createForm<CreateUser>({
...defaults,
// required due to several forms on the page
idPrefix: "flowbite3",
initialValue,
schema,
uiSchema,
onSubmit: ({ name }) => window.alert(`Hello, ${name}`),
});
</script>
<BasicForm {form} />
<pre>{JSON.stringify(getValueSnapshot(form), withFile, 2)}</pre>

<script lang="ts">
import { BasicForm, createForm, getValueSnapshot, type ExtraUiOptions } from "@sjsf/form";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../model";
import * as defaults from "./defaults";
const { extraUiOptions }: { extraUiOptions: ExtraUiOptions } = $props()
const form = createForm<CreateUser>({
...defaults,
// required due to several forms on the page
idPrefix: "skeleton4",
initialValue,
schema,
uiSchema,
onSubmit: ({ name }) => window.alert(`Hello, ${name}`),
// to work in Shadow DOM
extraUiOptions,
});
</script>
<BasicForm {form} />
<pre>{JSON.stringify(getValueSnapshot(form), withFile, 2)}</pre>

<script lang="ts">
import { BasicForm, createForm, getValueSnapshot } from "@sjsf/form";
import { setThemeContext } from "@sjsf/shadcn4-theme";
import * as components from "@sjsf/shadcn4-theme/new-york";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../model";
import * as defaults from "./defaults";
const form = createForm<CreateUser>({
...defaults,
// required due to several forms on the page
idPrefix: "shadcn4",
initialValue,
schema,
uiSchema,
onSubmit: ({ name }) => window.alert(`Hello, ${name}`),
});
//@ts-expect-error shadcn-svelte-extras
setThemeContext({ components });
</script>
<BasicForm {form} />
<pre>{JSON.stringify(getValueSnapshot(form), withFile, 2)}</pre>

This project includes modifications of code from react-jsonschema-form, which is licensed under the Apache License, Version 2.0. The rest of the project is under the MIT license.