---
title: "Form 组件 — zenit Zig UI"
description: "类型化表单状态、字段元信息和验证时机。业务值、dirty / touched、错误与 on_blur / on_submit 验证不需要散落在节点回调里。"
url: https://zenit.z.express/zh/components/form
language: zh-CN
alternate_en: https://zenit.z.express/components/form.md
alternate_es: https://zenit.z.express/es/components/form.md
alternate_ja: https://zenit.z.express/ja/components/form.md
alternate_ko: https://zenit.z.express/ko/components/form.md
alternate_fr: https://zenit.z.express/fr/components/form.md
alternate_de: https://zenit.z.express/de/components/form.md
project: zenit v0.1.0-alpha (Zig 0.15.2, macOS)
source: https://github.com/version-next/zenit
---

# Form

`ui.widgets.FormOf(T)`

类型化表单状态、字段元信息和验证时机。

[Video](https://zenit.z.express/media/stories/form.mp4?v=9ae9c123b3)

**BEHAVIOR CONTRACT**

业务值、dirty / touched、错误与 on\_blur / on\_submit 验证不需要散落在节点回调里。

**RECORDED INTERACTION**

Harness 点击 Submit，required 字段显示校验结果。

`examples/storybook/stories.zig:3140`

```zig
pub fn buildForm(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 12);
    _ = try ui.widgets.FormOf(DemoForm).create(scope, .{ .name = "", .email = "" }, .{ .trigger = .on_blur });
    // 表单字段 UI 用 Input 展示（FormOf 管校验状态；此 story 重在展示字段布局）
    try c.appendChild(a, try W.Input(.{ .label_text = "Name", .placeholder = "Full name", .width = 320, .required = true }).mount(scope, cx));
    try c.appendChild(a, try W.Input(.{ .label_text = "Email", .input_type = .email, .placeholder = "you@example.com", .width = 320, .required = true }).mount(scope, cx));
    try c.appendChild(a, try W.Button(.{ .label = "Submit", .variant = .primary }).mount(scope, cx));
    return c;
}
```

[在 GitHub 查看源码examples/storybook/stories.zig:3140](https://github.com/version-next/zenit/blob/HEAD/examples/storybook/stories.zig#L3140)

这是 Storybook 中该 story 的原样代码（zenit 5f9add5+wip 2026-09-30）。其中 `W` 即 `ui.widgets`，`col` / `row` / `label` 是 Storybook 内的布局小工具。
