Form / foldkit-form/metakit

Declarations

interface · packages/form/src/metakit.ts:72

interface Declarations<
  Fields extends Schema.Struct.Fields,
  Model,
  FieldKey extends string,
> {
  readonly constraints: {
    readonly [K in keyof Fields & string]: Constraint<K>
  }
  readonly can: <State, Emit>(
    model: Model,
    transition: Transition.Transition<State, Schema.Struct.Type<Fields>, Emit>,
    state?: Expr.PartialEnv<State>,
  ) => Verdict.Verdict<Node.Refusal>
  readonly disabled: <State, Emit>(
    model: Model,
    transition: Transition.Transition<State, Schema.Struct.Type<Fields>, Emit>,
    state?: Expr.PartialEnv<State>,
  ) => boolean
  readonly failures: (model: Model) => ReadonlyArray<RuleFailure<Fields>>
  readonly field: (model: Model, key: FieldKey) => FieldValidation.Field<Draft>
}

A form's declarations, read once from its input Schema.

Members

Declarations.constraints

property · packages/form/src/metakit.ts:74

readonly constraints: {
  readonly [K in keyof Fields & string]: Constraint<K>
}

Each key's constraint, by key.

Declarations.can

property · packages/form/src/metakit.ts:83

readonly can: <State, Emit>(
  model: Model,
  transition: Transition.Transition<State, Schema.Struct.Type<Fields>, Emit>,
  state?: Expr.PartialEnv<State>,
) => Verdict.Verdict<Node.Refusal>

Whether transition would go through with the values entered so far as its input, and state (the part of it known) as its state: True or False once the values its guard reads are known, Unknown while one is missing or not valid yet, or the guard calls an opaque function. False too for known values the guard cannot be evaluated over (a sum past ±(2^53−1)), carrying the refusal: the transition refuses them.

Declarations.disabled

property · packages/form/src/metakit.ts:93

readonly disabled: <State, Emit>(
  model: Model,
  transition: Transition.Transition<State, Schema.Struct.Type<Fields>, Emit>,
  state?: Expr.PartialEnv<State>,
) => boolean

Whether a submit control bound to transition should be disabled: true when can(model, transition, state) is False (the guard provably refuses the values entered so far), false when True or Unknown.

Declarations.failures

property · packages/form/src/metakit.ts:106

readonly failures: (model: Model) => ReadonlyArray<RuleFailure<Fields>>

The input Schema's own rules over several keys (Expr.refine on the struct) that the values entered so far break. A rule is broken only when it is False, or cannot be evaluated over the values entered (the Schema rejects those too): one reading a key not entered or not valid yet is undecided, and not here. A rule on one key is that key's own validation, which form.field already shows.

Declarations.field

property · packages/form/src/metakit.ts:111

readonly field: (model: Model, key: FieldKey) => FieldValidation.Field<Draft>

form.field, made Invalid by each broken rule that reads key, its message after the key's own errors, as the form shows its marks.