createAutoForm
createAutoForm(
plugin): <TTable,TNested>(__namedParameters) =>Element
Defined in: packages/forms/src/auto-form.tsx:448
Create an AutoForm React component bound to a specific UI FormPlugin.
The returned component introspects a Drizzle table via introspectTable, builds validation via createResolver, and renders fields using the plugin’s components. Supports:
- Create and edit modes —
mode="create"(default) starts empty,mode="edit"pre-fills fromdata. - Per-field overrides via FieldConfig: labels, placeholders, hidden,
defaults, custom components, custom validation,
readOnly, andcomputed. - Column exclusion via the
excludeprop. - Nested parent-child tables via the
nestedprop. Each entry is introspected like the parent table and rendered as auseFieldArraywith add / remove / reorder controls. The submitted value type is inferred fromtable+ each nestedtable, soonSubmitis fully typed without manual generics or casts. - Computed fields via
fields[name].computed. Computed fields are recalculated whenever any watched value changes (including nested rows) and pushed into the form viasetValue. - External react-hook-form instances via the
formprop.
Parameters
Section titled “Parameters”plugin
Section titled “plugin”A FormPlugin providing the UI components for rendering.
Returns
Section titled “Returns”A generic React component (AutoForm) that accepts AutoFormProps.
<
TTable,TNested>(__namedParameters):Element
Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable extends Table<TableConfig<Column<any, object, object>>> = SQLiteTable<TableConfig>
TNested
Section titled “TNested”TNested extends readonly NestedTableConfig[] | undefined = undefined
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”AutoFormProps<TTable, TNested>
Returns
Section titled “Returns”Element
Example
Section titled “Example”import { createAutoForm, createFormPlugin } from "@cfast/forms";
const plugin = createFormPlugin({ components: joyComponents });const AutoForm = createAutoForm(plugin);
// Recipe + ingredients + computed totals — fully inferred, no casts.<AutoForm table={recipes} nested={[ { table: ingredients, foreignKey: "recipeId", min: 1, reorderable: true, }, ]} fields={{ totalCalories: { computed: (values) => (values.ingredients as Array<{ calories: number; amount: number }> ?? []) .reduce((sum, ing) => sum + (ing.calories * ing.amount) / 100, 0), readOnly: true, }, }} onSubmit={async (values) => { // values.title: string, values.ingredients: Array<InferRow<typeof ingredients>> }}/>