Form / foldkit-form
Nested input
A key mapped with Relation.nested
holds child rows, each managed as a Model of the nested form:
ts
const NewComment = Entity.input(Blog.Comment, Schema.Struct({ body: Schema.String }))
const CreatePost = Entity.input(
Blog.Post,
Schema.Struct({ title: Schema.String, comments: Schema.Array(NewComment.schema) }),
{ comments: Relation.nested(Blog.Post.relations.comments, NewComment) },
)
// The form that edits a comment alone is the form a post's form nests.
const CommentForm = Form.make('Comment', NewComment, { inputs: { body: Input.multiline() } })
const PostForm = Form.make('PostForm', CreatePost, { nested: { comments: CommentForm } })
PostForm.row('comments', 'r0').Changed({ key: 'body', value: 'First' }) // a Message of PostForm
PostForm.nested.comments // CommentForm
PostForm.Message.RowAdded({ key: 'comments' })
PostForm.Message.RowRemoved({ key: 'comments', row: 'r0' })
PostForm.rows(PostForm.initial, 'comments') // [{ id, model }], each a Model of the nested form| The key is | Rows |
|---|---|
Required one relation | One row from the start; stays present |
Optional one relation | Zero or one row; empty submits null/undefined |
many relation | Zero or more rows |
- Pass
nested: { comments: CommentForm }with a form built from the same target input (omitting it generates a default form inheritingmessagesanddebounce). PostForm.row('comments', id)constructs typed Messages (Changed,Blurred,Searched,RowAdded,send(msg)) targetingmodel.rows; stale row IDs are ignored and row IDs are unique across the form's lifetime.- Nested controls have kind
Nested(Input.Nested.is(control)), holding{ cardinality, optional, form }. Submittedvalidates every row, waits on row async checks, surfaces list-level errors (such asSchema.isMaxLength(5)) inmodel.errors, andfillpopulates nested rows recursively.