Form System API | Dashforge-UI
DocsStarter Kits
v0.1.0-alpha

API Reference

Complete reference for Form System APIs.

DashForm

Main form provider component

The DashForm component wraps your form and provides the reactive engine, reactions, and runtime store.

import { DashForm } from '@dashforge/ui';

<DashForm
  reactions={reactions}
  defaultValues={{ country: 'United States' }}
  onSubmit={(data) => console.log(data)}
>
  {/* form fields */}
</DashForm>
PropTypeDefaultDescription
reactionsReactionDefinition[][]Array of reaction definitions for dynamic behavior
onSubmit(data: FormValues) => void | Promise<void>requiredForm submission handler
defaultValuesPartial<FormValues>-Initial form values
childrenReact.ReactNoderequiredForm fields and content

ReactionDefinition

Reaction configuration object

Reactions are defined as objects with these properties:

PropTypeDefaultDescription
idstringrequiredUnique identifier
watchstring[]requiredField names to watch
when(ctx: WhenContext) => boolean-Optional condition
run(ctx: RunContext) => void | Promise<void>requiredEffect to execute

RunContext

Context object passed to reaction run function

The run context provides methods for reading/writing form state:

PropTypeDefaultDescription
getValue<T>(name)(name: string) => T-Read field value
setValue(name, value)(name: string, value: unknown) => void-Update field value
getRuntime<TData>(name)(name: string) => FieldRuntimeState<TData>-Read runtime state
setRuntime<TData>(name, patch)(name: string, patch: Partial<FieldRuntimeState<TData>>) => void-Update runtime state
beginAsync(key)(key: string) => number-Start async operation
isLatest(key, id)(key: string, requestId: number) => boolean-Check if response is valid

FieldRuntimeState

Runtime metadata structure

Runtime state stores async metadata separate from form values:

interface FieldRuntimeState<TData = unknown> {
  status: 'idle' | 'loading' | 'ready' | 'error';
  data: TData | null;
  error: string | null;
}
PropTypeDefaultDescription
status'idle' | 'loading' | 'ready' | 'error''idle'Current operation status
dataTData | nullnullRuntime data (e.g., options)
errorstring | nullnullError message if status is error

visibleWhen

Conditional visibility prop

All form components accept a visibleWhen prop for conditional rendering:

visibleWhen?: (engine: Engine) => boolean

// Example
<TextField
  name="companyName"
  label="Company Name"
  visibleWhen={(engine) => 
    engine.getNode('accountType')?.value === 'business'
  }
/>

optionsFromFieldData

Dynamic options prop

Select and Autocomplete components can load options from runtime state:

<Select
  name="state"
  label="State"
  optionsFromFieldData
/>

// Runtime state structure expected:
{
  status: 'ready',
  data: {
    options: ['California', 'Texas', 'New York']
  }
}

On This Page