Form / foldkit-form

foldkit-form

A form as a Foldkit Submodel: built from the input an operation accepts, holding what the user is typing, and handing the parent a decoded value when it is valid. It adds no state system. Field state is Foldkit core's fieldValidation, and the form is a foldkit-bundle Bundle the parent places like any other.

Status: headless. It owns the Model, Messages, validation, and a description of each control, and draws nothing. foldkit-mixins-form draws it through Mixins slots; or draw from controls yourself.

What it owns

FactOwner
What may be submitted, and when it is validthe input Schema.Struct
What each input key means (a field, a relation's id)Entity.input
The draft in each control, and whether it has been checkedfoldkit-form, in the parent's Model
What happens to a submitted valuethe parent: a Remote mutation, a Sync operation, a plain update
Whether a submit is in flight, and its failurewhoever performs it; not the form
The options of a relation pickerthe application; the form only names the target Entity

Mental model

Schema.Struct (the operation's input)
        +
Entity.input (what each key means)
        |
        v
   Form.make ──► controls: key · control · label · required      (draw these)
        |
        v
     Bundle
   Model: one fieldValidation Field per key, holding the draft
   Changed / Blurred ──► validate the draft against the key's schema
   Submitted ──► every key valid, input decoded ──► out Message { value }

A draft is what the control holds, which is not the value it submits. A number being typed is text ("4." is a fine thing to have typed), an unchosen relation is "". The draft becomes a value only when it is checked.

Install

sh
pnpm add effect foldkit foldkit-bundle foldkit-entity foldkit-form