Skip to content
Playground Form Builder

svelte-jsonschema-form

Svelte 5 library for creating forms based on JSON schema.

Choose your favorite theme:

Terminal window
npm i @sjsf/form @sjsf/ajv8-validator ajv@8 @sjsf/basic-theme

Usage

<script lang="ts">
import { createForm, BasicForm, getValueSnapshot } from "@sjsf/form";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../data";
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>

This theme is not affiliated with, endorsed by, or sponsored by "daisyUI" brand.

Terminal window
npm i @sjsf/form @sjsf/ajv8-validator ajv@8 @sjsf/daisyui5-theme

Usage

<script lang="ts">
import { BasicForm, createForm, getValueSnapshot } from "@sjsf/form";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../data";
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>

This theme is not affiliated with, endorsed by, or sponsored by "Flowbite" brand.

Terminal window
npm i @sjsf/form @sjsf/ajv8-validator ajv@8 @sjsf/flowbite3-theme

Usage

<script lang="ts">
import { BasicForm, createForm, getValueSnapshot } from "@sjsf/form";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../data";
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>

This theme is not affiliated with, endorsed by, or sponsored by "Skeleton" brand.

Terminal window
npm i @sjsf/form @sjsf/ajv8-validator ajv@8 @sjsf/skeleton4-theme

Usage

<script lang="ts">
import { BasicForm, createForm, getValueSnapshot, type ExtraUiOptions } from "@sjsf/form";
import {
schema,
uiSchema,
initialValue,
type CreateUser,
withFile,
} from "../data";
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>

This theme is not affiliated with, endorsed by, or sponsored by "shadcn-svelte" brand.

Terminal window
npm i @sjsf/form @sjsf/ajv8-validator ajv@8 @sjsf/shadcn4-theme

Usage

<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 "../data";
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.