Skip to content

SchemaBuilder ​

What createSchemaBuilder returns. Its methods are plain functions, so they can be destructured: const { build, validate } = createSchemaBuilder().

Generics ​

Definition ​

Methods ​

build ​

ts
const schema = builder.build(json)
const schema = builder.build<TInput, TOutput>(json)

Checks the definition and builds the Valibot schema of the whole form: an object schema with a key for each field, in a v.pipe() with one check that runs every form rule when it has any. Throws one DefinitionError with every issue. With your input type, and your output type when it differs, the schema is typed as a TypedBuiltSchema. See TypeScript.

validate ​

ts
const result = builder.validate(json)

Every issue in a definition, in document order, as a ValidateResult. It never throws, whatever json is. See checking definitions.

defineForm ​

ts
const definition = builder.defineForm(definition)

Types a definition written in TypeScript against the builder's registries and extensions, and returns it unchanged. See TypeScript and TypedForm.

getInitialInput ​

ts
const input = builder.getInitialInput(json)

Formisch's initialInput: each field's default, nested the way the value is, the builder's own container types included. A container of kind object gives an object, and one of kind array without a default gives []. It never throws, and leaves out a field with issues. A field that conditions clear when the form starts starts blank.

getItemInput ​

ts
const input = builder.getItemInput(field)

The input of a new item of a list, for Formisch's insert(): an object of the defaults of its fields, or the default of its of field. Undefined for a field that isn't a container of kind array. It never throws.

getFieldTree ​

ts
const fields = builder.getFieldTree(json)

The definition's fields as a tree of FieldNodes, each with its role, for a renderer. Throws a DefinitionError like build().

getLayout ​

ts
const layout = builder.getLayout(json)

The definition's layout as a FormLayout, with every reference resolved: its steps, each a tree of sections, rows, slots and fields. Without a layout, one step with every field in order. Throws a DefinitionError like build().

getVisibility ​

ts
const visibility = builder.getVisibility(json)

What the conditions of the builder's extensions hide, for any input, as a Visibility. Without extensions or conditions, nothing is hidden. Throws a DefinitionError like build(). See conditions.

walkFields ​

ts
for (const field of builder.walkFields(json)) {
  // ...
}

Every field of the definition, at every depth, in document order, as WalkedFields with their kinds, the builder's own container types included. A group or a list comes before its fields, and the fields of a list's items come once. It never throws, and a container with issues isn't walked into.

rulesForKind ​

ts
const rules = builder.rulesForKind(kind)

The registered rules that fit a field of kind, as [name, def] pairs, like for a rule picker. See listing rules.

Registries ​

kinds, fieldTypes, rules, formRules and extensions are the builder's registries: the built-in entries merged with yours.

Functions ​