Skip to content
Playground Form Builder

Standard Schema

You can use any validator that implements Standard Schema spec and can be converted to JSON Schema for the full form validation step.

<script lang="ts">
import {
BasicForm,
createForm,
type Schema,
type Validator,
} from "@sjsf/form";
import { createFormValueValidator } from "@sjsf/form/validators/standard-schema";
import { type } from "arktype";
import * as defaults from "@/components/form-defaults";
import { initialValue, uiSchema } from "../shared";
const schema = type({
"id?": "string>=8&/^\\d+$/",
"active?": "boolean",
"skills?": "(string>=5)[]>=4",
"multipleChoicesList?": "('foo'|'bar'|'fuzz')[]<=2",
});
type Value = typeof schema.infer;
const validator = {
...createFormValueValidator({ schema, uiSchema }),
isValid: () => true,
} satisfies Validator;
const form = createForm({
...defaults,
schema: schema.toJsonSchema({
dialect: "https://json-schema.org/draft-07/schema",
}) as Schema,
uiSchema,
validator,
initialValue: initialValue as Value,
});
</script>
<BasicForm {form} novalidate />
<pre>{JSON.stringify(form.value, null, 2)}</pre>

You can use isValid: () => true as long as the generated form does not contain the following keywords oneOf, anyOf and if,them,else.

In such cases, you will need a real Validator interface implementation (You can take it from another validator or write it yourself).

This validator supports async validation.

import { createAsyncFormValueValidator } from "@sjsf/form/validators/standard-schema";
const validator = {
...createAsyncFormValueValidator({ schema }),
};