webiny-form-model
它能做什么
这项技能在你的 AI 于 Webiny 平台构建表单时提供指导。适合希望以清晰、声明式的方式定义表单字段、布局和校验的开发者。
适用场景
- ✓当你需要用构建器为 Webiny 表单定义文本、日期或其他字段的时候。
- ✓当你需要在表单布局中使用标签页、行或分隔线的时候。
- ✓当字段需要根据其他字段的值显示、隐藏或校验的时候。
技能链接
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/admin/form-model/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请构建一个 Webiny 表单,包含标题、日期和状态;只有状态为已排期时,才显示日期字段。”
每周 5 个新技能,1 分钟读完。
工作原理
技能演示如何用可链式调用的构建器定义字段,用布局构建器排列它们,并添加校验或规则。字段也可以响应其他字段的值。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Form Model
TL;DR
The Form Model is Webiny's declarative form system. Define fields with a fluent builder API (fields.text(), fields.datetime(), etc.), arrange them with a layout builder (layout.row(), layout.tabs(), etc.), and validate with Zod schemas or imperative rules. Fields support conditional visibility, computed values, reactive context from other fields (.context()), and deeply nested object/list structures with templates (dynamic zones).
Field Types
All fields are created via the fields registry callback. Each builder method returns a chainable builder.
Text
fields.text();
Default renderer: textInput. Value: string | null.
fields.text().label("Title").placeholder("Enter title").required("Title is required")
fields.text().renderer("textarea", { rows: 4 })
fields.text().list().renderer("tags").defaultValue([])
fields.text().list().renderer("textInputs", { addItemLabel: "Add text" })
fields.text().list().renderer("textareas", { addItemLabel: "Add description" })
fields.text().renderer("codeEditor", { language: "html", height: 300 })
fields.text().options([
{ label: "Option A", value: "a" },
{ label: "Option B", value: "b" }
]) // auto-switches to "select" renderer
fields.text().options([...]).renderer("radioButtons")
fields.text().list().options([...]).renderer("checkboxes")
// Dynamic options — callback receives { field, form }, re-evaluated reactively
fields.text().options(({ form }) => {
const type = form.field("general.type").getValue();
return getOptionsForType(type);
})
Number
fields.number();
Default renderer: numberInput. Value: number | null. Auto-normalizes to number.
fields.number().label("Count").placeholder("0").required();
fields.number().list().renderer("numberInputs", { addItemLabel: "Add number" });
fields.number().options([
{ label: "Tier 1", value: 100 },
{ label: "Tier 2", value: 200 }
]);
Boolean
fields.boolean();
Default renderer: switch. Value: boolean | null.
fields.boolean().label("Featured").defaultValue(false);
DateTime
fields.datetime();
Default renderer: dateTimeInput. Pick a variant method to set the subtype:
| Variant | Value Format | Example |
|---|---|---|
.dateOnly() |
"2026-05-01" |
Holidays, due dates (birthdays: see the birthday picker below) |
.timeOnly() |
"14:30:00" |
Opening hours |
.withTimezone() |
"2026-05-01T14:30:00+02:00" |
Events tied to a locale |
.withoutTimezone() |
"2026-05-01T14:30:00.000Z" |
Timestamps, logs |
.monthOnly() |
"2026-05" |
Billing cycles |
.weekOnly({ startsOn: 1 }) |
"2026-W18" |
Sprint planning |
.yearOnly({ range: [2020, 2035] }) |
2026 (number) |
Fiscal years |
.dateRange() |
{ from: "...", to: "..." } |
Vacation requests |
.multipleDates() |
["2026-05-01", "2026-05-03"] |
Blackout dates |
.multipleMonths() |
["2026-01", "2026-03"] |
Seasonal availability |
.multipleYears({ range: [2020, 2035] }) |
[2024, 2025, 2026] |
Multi-year budgets |
Additional chainable methods:
.presets([
{ label: "Today", value: () => new Date() },
{ label: "In a week", value: () => addDays(new Date(), 7) }
])
.displayFormat("dd/MM/yyyy") // date-fns format tokens
.list() // switches renderer to "dateTimeInputs"
.dateGte("2026-01-01", "message?") // value must
常见问题
如何添加校验?
技能既支持 Zod schema,也支持简单的命令式规则。
字段之间能相互依赖吗?
能。技能涵盖条件可见性、禁用,以及响应其他字段值的字段。
默认使用哪种渲染器?
对于文本字段,技能说明默认渲染器是文本输入框,也可以切换为文本域或下拉选择等其他渲染器。
详情
作者的原始描述
Building forms with the FormModel system — field types, renderers, layout, validation, conditional rules, computed fields, and dynamic zones. Use this skill when the developer needs to define form fields with the builder API, choose renderers, build layouts with tabs/rows/separators, add validation (Zod or imperative), use conditional visibility/disable rules, create computed fields, or work with object fields and templates (dynamic zones).
repo: webiny/webiny-js
热度
- GitHub 星标
- 8.1k
- 排名
- #12576
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
prd-to-plan
8.1k帮你的智能体把产品需求文档转化为分阶段的计划,由许多小的端到端切片组成,并保存为 Markdown 文件。
webiny-admin-architect
8.1k教你的智能体如何为 Webiny 平台构建管理界面,使用其业务逻辑层和呈现器模式。
webiny-admin-permissions
8.1k教你的智能体为 Webiny 管理界面添加权限控制,包括自动生成的权限表单以及显示或隐藏检查。
webiny-new-entry-wizard
8.1k教你的智能体为 Webiny CMS 的新条目添加自定义设置向导,先收集几个字段,再预填条目表单。