Skip to Content
ContentAPIClassesClass: BasicFormBuilder<T>

Hero Hook Form API v2.5.1


Hero Hook Form API / BasicFormBuilder

Class: BasicFormBuilder<T>

Defined in: builders/BasicFormBuilder.ts:40 

Basic form field builder for creating form field configurations.

Description

Provides a fluent API for building form field configurations. This builder focuses on the most common use cases and eliminates the need for “as const” assertions. Use this for simple forms with standard field types.

Example

import { createBasicFormBuilder } from "@rachelallyson/hero-hook-form"; const fields = createBasicFormBuilder() .input("name", "Name") .input("email", "Email", "email") .textarea("message", "Message") .select("country", "Country", [ { label: "US", value: "us" }, { label: "CA", value: "ca" }, ]) .checkbox("newsletter", "Subscribe to newsletter") .build();

See

Type Parameters

T

T extends FieldValues

The form data type

Constructors

Constructor

new BasicFormBuilder<T>(): BasicFormBuilder<T>

Returns

BasicFormBuilder<T>

Methods

input()

input(name, label, type): this

Defined in: builders/BasicFormBuilder.ts:46 

Add an input field

Parameters

name

Path<T>

label

string

type

"text" | "email" | "tel" | "password"

Returns

this


textarea()

textarea(name, label, placeholder?): this

Defined in: builders/BasicFormBuilder.ts:64 

Add a textarea field

Parameters

name

Path<T>

label

string

placeholder?

string

Returns

this


select()

select(name, label, options): this

Defined in: builders/BasicFormBuilder.ts:78 

Add a select field

Parameters

name

Path<T>

label

string

options

object[]

Returns

this


autocomplete()

autocomplete(name, label, items, placeholder?): this

Defined in: builders/BasicFormBuilder.ts:96 

Add an autocomplete field

Parameters

name

Path<T>

label

string

items

object[]

placeholder?

string

Returns

this


checkbox()

checkbox(name, label): this

Defined in: builders/BasicFormBuilder.ts:116 

Add a checkbox field

Parameters

name

Path<T>

label

string

Returns

this


content()

content(title?, description?, options?): this

Defined in: builders/BasicFormBuilder.ts:129 

Add a content field for headers, questions, or custom content between fields

Parameters

title?

string | null

description?

string | null

options?
render?

(field) => ReactNode

className?

string

name?

Path<T>

Returns

this


switch()

switch(name, label, description?): this

Defined in: builders/BasicFormBuilder.ts:157 

Add a switch field

Parameters

name

Path<T>

label

string

description?

string

Returns

this


build()

build(): ZodFormFieldConfig<T>[]

Defined in: builders/BasicFormBuilder.ts:171 

Build the final field configuration array

Returns

ZodFormFieldConfig<T>[]