import {Forms} from "attio/client"

The schema is formed using the builder pattern. Objects can be nested arbitrarily deep.

Example

const schema = {
    name: Forms.string(),
    note: Forms.string().multiline(),
    nickname: Forms.string().optional(),
    age: Forms.number().min(18),
    numTokens: Forms.number().max(100),
    phoneNumbers: Forms.array(Forms.string()),
    addresses: Forms.array({
        street: Forms.string(),
        city: Forms.string(),
    }),
}

The allowed FormValues are:

Forms.string()

A string value. Required by default.

Mutators

.default(value : string)

Sets a default value to return when no value is entered by the user.

This is NOT the same as an “initial value”, which should be passed to the useForm() hook.

.multiline()

Will cause the string input to be multiline.

A <textarea /> rather than an <input type="text" /> in DOM-speak

.optional()

By default, strings are required. This will change that to let null, undefined, and "" pass validation.

Forms.number()

A numeric value. Required by default.

Mutators

.default(value : number)

Sets a default value to return when no value is entered by the user.

This is NOT the same as an “initial value”, which should be passed to the useForm() hook.

.optional()

By default, numbers are required. This will change that to let null and undefined pass validation.

.min(min: number)

Provide a minimum value. Validation will fail if the user inputs number < min.

.max(max: number)

Provide a maximum value. Validation will fail if the user inputs number > max.

Forms.array(FormValue | Record<string, FormValue>)

An array of other form values or objects of form values.

They are referenced with a name prop like "addresses[0].street".

Mutators

.optional()

By default, arrays are required. This will change that to let null and undefined pass validation.