components/form
Eingaben · 17 / 64

Form

ui.widgets.FormOf(T)

Typisierter Formularzustand, Feldmetadaten und Validierungszeitpunkt.

BEHAVIOR CONTRACT

Werte, dirty / touched, Fehler und die Validierung on_blur / on_submit liegen im Formular, nicht in Node-Callbacks.

RECORDED INTERACTION

Der Harness klickt Submit; Pflichtfelder zeigen ihre Validierung.

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;
}
Quellcode auf GitHub ansehenexamples/storybook/stories.zig:3140

Der unveränderte Quellcode der Story aus dem Storybook (zenit 5f9add5+wip 2026-09-30). W steht für ui.widgets; col / row / label sind kleine Layout-Helfer des Storybooks.

zenit · DoppellizenzKostenlos für Open-Source-Projekte unter GPL-3.0-only; Closed-Source- oder kommerzielle Produkte benötigen eine kommerzielle Lizenz.Kontakt zum Autor: zongyi.xzy#gmail.com (# durch @ ersetzen)zenit 5f9add5+wip 2026-09-30