Class FormSchemaBuilder

Builds schema which defines shape of the form values and type of validation errors. The schema is used not only for compile-time type-safety but also for runtime validation of form values. The schema can be defined top-level, so that it can be exported to nested Form components for usage together with useField hook.

Returns

FormSchema - used to interact with Formts API and point to specific form fields

Example

import { FormSchemaBuilder, FormFields } from "@virtuslab/formts"

const Schema = new FormSchemaBuilder()
.fields({
name: FormFields.string(),
age: FormFields.number(),
})
.errors<string>()
.build()

Hierarchy

  • FormSchemaBuilder

Constructors

Properties

Methods

Constructors

  • Builds schema which defines shape of the form values and type of validation errors. The schema is used not only for compile-time type-safety but also for runtime validation of form values. The schema can be defined top-level, so that it can be exported to nested Form components for usage together with useField hook.

    Returns FormSchemaBuilder

    FormSchema - used to interact with Formts API and point to specific form fields

    Example

    import { FormSchemaBuilder, FormFields } from "@virtuslab/formts"

    const Schema = new FormSchemaBuilder()
    .fields({
    name: FormFields.string(),
    age: FormFields.number(),
    })
    .errors<string>()
    .build()

Properties

decoders: {} = ...

Type declaration

    Methods

    • Define form errors to be used by FormValidatorBuilder.

      Type Parameters

      • Err

      Returns SchemaBuilder$Errors<Err>

      Example

      new FormSchemaBuilder()
      .errors<MyErrorCodesEnum>()
    • Define form fields as dictionary of decoders. Use FormFields import.

      Type Parameters

      • V extends object

      Parameters

      • fields: DecodersMap<V>

      Returns SchemaBuilder$Fields<V>

      Example

      new FormSchemaBuilder()
      .fields({
      name: FormFields.string(),
      age: FormFields.number(),
      })

    Generated using TypeDoc