Skip to content
Playground
You’re viewing the documentation for v2. Looking for v1? Find it here.

svelte-jsonschema-form

Svelte 5 library for creating forms based on JSON schema.

Installation

Choose your favorite theme:

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

Usage

<script lang="ts">
import { createForm, BasicForm } from "@sjsf/form";
import { resolver } from "@sjsf/form/resolvers/basic";
import { translation } from "@sjsf/form/translations/en";
import { theme } from "@sjsf/basic-theme";
import "@sjsf/basic-theme/extra-widgets/textarea-include";
import { schema, uiSchema, initialValue } from "./_schema";
import { createValidator } from "./_validator";
import { onSubmit } from "./_on-submit";
const idPrefix = "basic";
const validator = createValidator(idPrefix);
const form = createForm({
idPrefix,
validator,
theme,
resolver,
initialValue,
schema,
uiSchema,
translation,
onSubmit,
});
</script>
<BasicForm {form} />
<pre>{JSON.stringify(form.value, null, 2)}</pre>

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

Usage

<script lang="ts">
import { BasicForm, createForm } from "@sjsf/form";
import { resolver } from "@sjsf/form/resolvers/basic";
import { translation } from "@sjsf/form/translations/en";
import { theme } from "@sjsf/daisyui-theme";
import "@sjsf/daisyui-theme/extra-widgets/textarea-include";
import { createAstro } from "@/astro.svelte";
import { schema, uiSchema, initialValue } from "./_schema";
import { createValidator } from "./_validator";
import { onSubmit } from "./_on-submit";
const idPrefix = "daisyui";
const validator = createValidator(idPrefix);
const form = createForm({
idPrefix,
validator,
resolver,
theme,
initialValue,
schema,
uiSchema,
translation,
onSubmit,
});
const astro = createAstro();
</script>
<BasicForm
{form}
style="background-color: transparent; margin-bottom: 1rem;"
data-theme={astro.darkOrLight}
/>
<pre>{JSON.stringify(form.value, null, 2)}</pre>

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

Usage

<script lang="ts">
import { BasicForm, createForm } from "@sjsf/form";
import { resolver } from "@sjsf/form/resolvers/basic";
import { translation } from "@sjsf/form/translations/en";
import { theme } from "@sjsf/daisyui5-theme";
import "@sjsf/daisyui5-theme/extra-widgets/textarea-include";
import { createAstro } from "@/astro.svelte";
import { schema, uiSchema, initialValue } from "./_schema";
import { createValidator } from "./_validator";
import { onSubmit } from "./_on-submit";
const idPrefix = "daisyui5";
const validator = createValidator(idPrefix);
const form = createForm({
idPrefix,
validator,
resolver,
theme,
initialValue,
schema,
uiSchema,
translation,
onSubmit,
});
const astro = createAstro();
</script>
<BasicForm
{form}
style="background-color: transparent; margin-bottom: 1rem;"
data-theme={astro.darkOrLight}
/>
<pre>{JSON.stringify(form.value, null, 2)}</pre>

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

Usage

<script lang="ts">
import { BasicForm, createForm } from "@sjsf/form";
import { resolver } from "@sjsf/form/resolvers/basic";
import { translation } from "@sjsf/form/translations/en";
import { theme } from "@sjsf/flowbite3-theme";
import "@sjsf/flowbite3-theme/extra-widgets/textarea-include";
import { createAstro } from "@/astro.svelte";
import { schema, uiSchema, initialValue } from "./_schema";
import { createValidator } from "./_validator";
import { onSubmit } from "./_on-submit";
const idPrefix = "flowbite3";
const validator = createValidator(idPrefix);
const form = createForm({
idPrefix,
validator,
resolver,
theme,
initialValue,
schema,
uiSchema,
translation,
onSubmit,
});
const astro = createAstro();
</script>
<BasicForm {form} class="flex flex-col gap-4 mb-4 {astro.darkOrLight}" />
<pre>{JSON.stringify(form.value, null, 2)}</pre>

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

Usage

<script lang="ts">
import { BasicForm, createForm } from "@sjsf/form";
import { resolver } from "@sjsf/form/resolvers/basic";
import { translation } from "@sjsf/form/translations/en";
import { theme } from "@sjsf/skeleton3-theme";
import "@sjsf/skeleton3-theme/extra-widgets/textarea-include";
import { createAstro } from "@/astro.svelte";
import { schema, uiSchema, initialValue } from "./_schema";
import { createValidator } from "./_validator";
import { onSubmit } from "./_on-submit";
const idPrefix = "skeleton";
const validator = createValidator(idPrefix);
const form = createForm({
idPrefix,
validator,
resolver,
theme,
initialValue,
schema,
uiSchema,
translation,
onSubmit,
});
const astro = createAstro();
</script>
<BasicForm
{form}
class="flex flex-col gap-4 {astro.darkOrLight}"
style="margin-bottom: 1rem;"
data-theme="cerberus"
/>
<pre>{JSON.stringify(form.value, null, 2)}</pre>

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

Usage

<script lang="ts">
import { BasicForm, createForm } from "@sjsf/form";
import { resolver } from "@sjsf/form/resolvers/basic";
import { translation } from "@sjsf/form/translations/en";
import { theme, setThemeContext } from "@sjsf/shadcn-theme";
import { components } from "@sjsf/shadcn-theme/default";
import "@sjsf/shadcn-theme/extra-widgets/textarea-include";
import { createAstro } from "@/astro.svelte";
import { schema, uiSchema, initialValue } from "./_schema";
import { createValidator } from "./_validator";
import { onSubmit } from "./_on-submit";
const idPrefix = "shadcn";
const validator = createValidator(idPrefix);
const form = createForm({
idPrefix,
validator,
resolver,
theme,
initialValue,
schema,
uiSchema,
translation,
onSubmit,
});
const astro = createAstro();
setThemeContext({ components });
</script>
<BasicForm {form} class="flex flex-col gap-4 {astro.darkOrLight}" />
<pre style="padding-top: 1rem;">{JSON.stringify(form.value, null, 2)}</pre>

License

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.