v0.1.0-alpha
官网Home
components/form
输入与表单Inputs · 17 / 64

Form

ui.widgets.FormOf(T)

类型化表单状态、字段元信息和验证时机。Typed form state, field metadata and validation timing.

BEHAVIOR CONTRACT

业务值、dirty / touched、错误与 on_blur / on_submit 验证不需要散落在节点回调里。Values, dirty / touched, errors and on_blur / on_submit validation live in the form, not in node callbacks.

RECORDED INTERACTION

Harness 点击 Submit,required 字段显示校验结果。The harness clicks Submit; required fields show their validation.

examples/storybook/stories.zig:3140
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 查看源码View source on GitHubexamples/storybook/stories.zig:3140

这是 Storybook 中该 story 的原样代码(zenit 5f9add5+wip 2026-09-30)。其中 W 即 ui.widgets,col / row / label 是 Storybook 内的布局小工具。The story's verbatim source from the Storybook (zenit 5f9add5+wip 2026-09-30). W is ui.widgets; col / row / label are small Storybook layout helpers.

zenit · 双授权Dual-licensed开源项目可按 GPL-3.0-only 免费使用;闭源或商业产品需要商业授权。Free for open-source projects under GPL-3.0-only; closed-source or commercial products need a commercial license.可联系作者:Contact the author: zongyi.xzy#gmail.com(# 换成 @) (replace # with @)zenit 5f9add5+wip 2026-09-30