ui/build/form/form\_state.svelte
ui/build/form/form_state.svelte
Classes
FormState
Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:111
Type Parameters
| Type Parameter | Default type |
|---|---|
Schema extends FormSchema |
- |
TReturn |
unknown |
E |
Cause.UnknownError |
Constructors
Constructor
new FormState<Schema, TReturn, E>(config): FormState<Schema, TReturn, E>;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:197
Parameters
| Parameter | Type |
|---|---|
config |
FormStateConfig<Schema, TReturn, E> |
Returns
FormState<Schema, TReturn, E>
Properties
applyDraft
applyDraft: () => boolean;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:267
Apply draft to working copy if one exists. Returns true if draft was applied.
Returns
boolean
baseline
baseline: InferSchema<Schema>;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:171
Baseline: The reference point for diff calculation. Formula: baseline = serverState ?? defaultState This is what W is compared against to compute Δ.
clearDraft
clearDraft: () => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:271
Explicitly clear the draft from storage.
Returns
void
clearErrors
clearErrors: () => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:332
Returns
void
clearFieldError
clearFieldError: (path) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:333
Parameters
| Parameter | Type |
|---|---|
path |
string |
Returns
void
delta
delta: object[];Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:177
Delta (Δ): RFC 6902 JSON Patch operations from baseline to working copy. Represents the "distance traveled" from S (or D) to W. Uses identity-aware comparison for arrays with 'id' or 'id' keys.
op
readonly op: "replace" | "add" | "remove";path
readonly path: string;value?
readonly optional value?: unknown;
destroy
destroy: () => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:276
Cleanup draft storage listeners and pending tasks. Call this when the form component is destroyed.
Returns
void
disabled
disabled: boolean;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:138
Whether the form is disabled (reactive)
errorMessage
errorMessage: string | null;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:147
Error message from last failed submission
errors
errors: object;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:151
Validation errors
fieldErrors
fieldErrors: Record<string, string[]>;formErrors
formErrors: string[];
getArrayItemTemplate
getArrayItemTemplate: (arrayPath) => unknown;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:302
Get the item template for an array path (for ListBlock new items). Returns the first item from defaultState array, or empty object.
Parameters
| Parameter | Type | Description |
|---|---|---|
arrayPath |
string |
Dot-notation path to the array |
Returns
unknown
getData
getData: () => InferSchema<Schema>;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:235
Get the current working copy.
Returns
InferSchema<Schema>
getDefaultState
getDefaultState: () => InferSchema<Schema>;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:295
Get the current default state (D).
Returns
InferSchema<Schema>
getDeltaForPath
getDeltaForPath: (path) => object[];Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:323
Get delta operations for a specific field path. Useful for highlighting changed fields in the UI.
Parameters
| Parameter | Type |
|---|---|
path |
string |
Returns
object[]
getFieldErrors
getFieldErrors: (path) => string[];Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:335
Parameters
| Parameter | Type |
|---|---|
path |
string |
Returns
string[]
getServerState
getServerState: () =>
| InferSchema<Schema>
| null;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:281
Get the current server state (S). Derived from the getter - parent controls this value.
Returns
| InferSchema<Schema>
| null
getValue
getValue: <K>(path) => Get<InferSchema<Schema>, K>;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:239
Get a field value from working copy by dot-notation path.
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
| Parameter | Type |
|---|---|
path |
K |
Returns
Get<InferSchema<Schema>, K>
handleSubmit
handleSubmit: (event) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:353
Handle form submit event.
Parameters
| Parameter | Type |
|---|---|
event |
Event |
Returns
void
hasChangesForPath
hasChangesForPath: (path) => boolean;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:331
Check if a specific field path has changes in delta. Useful for conditionally styling dirty fields.
NOTE: Since Δ is computed on normalized data (where arrays with IDs are objects), we need to handle both positional and identity-based paths.
Parameters
| Parameter | Type |
|---|---|
path |
string |
Returns
boolean
hasDraft
hasDraft: boolean;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:191
hasDraft: Whether a persisted draft exists in localStorage. Only relevant when draftKey is configured.
hasServerState
hasServerState: boolean;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:196
hasServerState: Whether we have authoritative server data. false when creating new entity, true when editing existing.
hasValidationErrors
hasValidationErrors: boolean;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:156
Whether client-side validation failed on the last submit attempt
isDirty
isDirty: boolean;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:186
isDirty: Whether the working copy differs from baseline. True when Δ contains any operations.
isSubmitting
isSubmitting: boolean;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:143
Whether a submission is in progress
lastResult
lastResult: TReturn | undefined;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:145
Result from last successful submission
loadDraft
loadDraft: () =>
| InferSchema<Schema>
| null;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:262
Load draft data without applying it. Returns the raw draft for custom merging, or null if no draft.
Returns
| InferSchema<Schema>
| null
pushArrayItem
pushArrayItem: (arrayPath, item?) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:310
Push a new item to an array in workingCopy, using defaultState template. Triggers onDataChange hook for derived value recalculation.
Parameters
| Parameter | Type | Description |
|---|---|---|
arrayPath |
string |
Dot-notation path to the array |
item? |
unknown |
Optional custom item (defaults to array item template from defaultState) |
Returns
void
removeArrayItem
removeArrayItem: (arrayPath, index) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:318
Remove an item from an array in workingCopy by index. Triggers onDataChange hook for derived value recalculation.
Parameters
| Parameter | Type | Description |
|---|---|---|
arrayPath |
string |
Dot-notation path to the array |
index |
number |
Index of item to remove |
Returns
void
removeHook
removeHook: <K>(hookName) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:213
Remove a hook callback.
Type Parameters
| Type Parameter |
|---|
K extends keyof FormStateHooks<InferSchema<Schema>> |
Parameters
| Parameter | Type |
|---|---|
hookName |
K |
Returns
void
reset
reset: () => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:257
Reset working copy to baseline (S or D) and clear draft. After reset: W = baseline, Δ becomes empty.
Returns
void
setData
setData: (data, options?) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:224
Update working copy with deep merge support.
Pass replace: true to replace entirely instead of merging.
Automatically persists to draft storage and triggers auto-submit.
Parameters
| Parameter | Type | Description |
|---|---|---|
data |
Partial<InferSchema<Schema>> |
Partial data to merge, or full data if replacing |
options? |
{ force?: boolean; replace?: boolean; triggerHooks?: boolean; } |
- |
options.force? |
boolean |
Bypass disabled check for programmatic updates (e.g., streaming) |
options.replace? |
boolean |
Whether to replace instead of merge |
options.triggerHooks? |
boolean |
Whether to trigger onDataChange hook (default: true) |
Returns
void
setDefaultState
setDefaultState: <K>(path, value) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:290
Update default state at a specific path. Auto-merges to workingCopy if the path has no value (null/undefined). Used by authored form runtimes to register per-field defaults (defaultValue callbacks).
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
path |
K |
Dot-notation path to set |
value |
Get<InferSchema<Schema>, K> |
Default value for that path |
Returns
void
setDefaultValueAtPath
setDefaultValueAtPath: (path, value) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:291
Parameters
| Parameter | Type |
|---|---|
path |
string |
value |
unknown |
Returns
void
setFieldError
setFieldError: (path, messages) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:334
Parameters
| Parameter | Type |
|---|---|
path |
string |
messages |
string | string[] |
Returns
void
setHook
setHook: <K>(hookName, callback) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:209
Register a hook callback for lifecycle events.
Type Parameters
| Type Parameter |
|---|
K extends keyof FormStateHooks<InferSchema<Schema>> |
Parameters
| Parameter | Type |
|---|---|
hookName |
K |
callback |
FormStateHooks<InferSchema<Schema>>[K] |
Returns
void
setValue
setValue: <K>(path, value, options?) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:245
Set a field value in working copy by dot-notation path. Automatically persists to draft storage and triggers auto-submit. Pass triggerHooks: false to skip onDataChange (e.g. when writing derived values).
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
| Parameter | Type |
|---|---|
path |
K |
value |
Get<InferSchema<Schema>, K> |
options? |
{ force?: boolean; triggerHooks?: boolean; } |
options.force? |
boolean |
options.triggerHooks? |
boolean |
Returns
void
setValueAtPath
setValueAtPath: <K>(path, value, options?) => void;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:249
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
| Parameter | Type |
|---|---|
path |
K |
value |
Get<InferSchema<Schema>, K> |
options? |
{ force?: boolean; triggerHooks?: boolean; } |
options.force? |
boolean |
options.triggerHooks? |
boolean |
Returns
void
submit
submit: (options?) => Effect<TReturn | null, UnknownError | E>;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:347
Submit the form. Validates W, calls remoteFn if provided, and handles success/error states.
On success:
- S ← W (working copy becomes new server state)
- Clear draft storage
- Δ becomes empty (since S now equals W)
Parameters
| Parameter | Type | Description |
|---|---|---|
options? |
{ silent?: boolean; } |
{ silent?: boolean } - If true, don't show success toast |
options.silent? |
boolean |
- |
Returns
Effect<TReturn | null, UnknownError | E>
submitSuccessMessage
submitSuccessMessage: string | null;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:149
Success message text while the last submission is in the success state (before commit/reset).
validationErrorMessage
validationErrorMessage: string | null;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:158
First validation error message, when hasValidationErrors is true
Type Aliases
AutoSubmitConfig
type AutoSubmitConfig = object;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:32
Properties
FormStateConfig
type FormStateConfig<Schema, TReturn, E> = object;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:43
Type Parameters
| Type Parameter | Default type |
|---|---|
Schema extends FormSchema |
- |
TReturn |
- |
E |
Cause.UnknownError |
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
autoSubmit? |
MaybeGetter< | AutoSubmitConfig | undefined> |
Auto-submit configuration. When enabled, form auto-submits on data change. Can be a getter for reactivity. | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:96 |
defaultState? |
MaybeGetter<InferSchema<Schema>> |
Default State (D): Static fallback structure. | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:49 |
description? |
MaybeGetter<string> |
Optional description for debugging | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:77 |
disabled? |
MaybeGetter<boolean> |
Whether the form is disabled. Can be a getter for reactivity. | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:81 |
draftKey? |
MaybeGetter<string[]> |
Key parts for draft persistence. If provided, enables automatic draft save/load. The draft storage IS the Working Copy (W) - persisted to localStorage. On hydration: W = draft ?? serverState ?? defaultState Can be a getter for reactivity. Examples draftKey: ['create_form', collectionId] draftKey: () => ['unified_form', entityId] |
apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:91 |
onSuccess? |
(result) => Effect.Effect<void> | void |
Called after successful submission | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:59 |
remoteFn? |
RemoteFnGetter<Schema, TReturn, E> |
Remote function to call on submit. | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:57 |
schema |
MaybeGetter<Schema> |
Schema for validation | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:45 |
serverState? |
MaybeGetter< | InferSchema<Schema> | null> |
Server State (S): Authoritative data from database. | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:53 |
submitSuccessBehavior? |
MaybeGetter<SubmitSuccessBehavior> |
Post-submit behavior after a successful submission. - none: keep current working copy as-is - commit: treat submitted payload as new baseline and clear dirty state - reset: reset to baseline and clear draft/errors | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:66 |
successMessage? |
MaybeGetter<string | null> |
Toast message on success. Set to null to disable. | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:70 |
transform? |
MaybeGetter<(data) => InferSchema<Schema>> |
Transform data before validation/submission | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:68 |
translate? |
TranslateFn |
Catalog-backed translate handle for built-in copy (success toast, validation summary, generic failure). When omitted, English fallbacks are used. | apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:75 |
FormStateHooks
type FormStateHooks<T> = object;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:101
Hook callbacks for FormState lifecycle events
Type Parameters
| Type Parameter |
|---|
T |
Properties
FormSubmitFn
type FormSubmitFn<Schema, TReturn, E> = (data) => Effect.Effect<TReturn, E>;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:30
Plain submit handler (sync or async). Framework-specific remote callables that share this shape remain compatible at runtime.
Type Parameters
| Type Parameter | Default type |
|---|---|
Schema extends FormSchema |
- |
TReturn |
- |
E |
Cause.UnknownError |
Parameters
| Parameter | Type |
|---|---|
data |
InferSchema<Schema> |
Returns
Effect.Effect<TReturn, E>
SubmitSuccessBehavior
type SubmitSuccessBehavior = "none" | "commit" | "reset";Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:40
TranslateFn
type TranslateFn = (key, vars?) => string;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:24
Catalog-backed translation handle, threaded in so this state class never renders hardcoded copy.
Parameters
| Parameter | Type |
|---|---|
key |
string |
vars? |
MessageVars |
Returns
string
Functions
maybeAsync()
function maybeAsync<A>(evaluate): Effect<Awaited<A>, UnknownError>;Defined in: apps/website/.api-docs-entry/ui/build/form/form_state.svelte.d.ts:110
Run a possibly-synchronous callback and await its result through Effect.
Type Parameters
| Type Parameter |
|---|
A |
Parameters
| Parameter | Type |
|---|---|
evaluate |
() => A |
Returns
Effect<Awaited<A>, UnknownError>
References
FormSchema
Re-exports FormSchema
InferSchema
Re-exports InferSchema