FormField
为控件添加标签、帮助和错误说明。
实时预览
正在加载预览…
参数配置
全部字段 13
FormFieldOptions
Go 代码
Go
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
nui.FormField(c.Key("field"), t, nui.FormFieldOptions{Label: "Project", Help: "Use a name your team will recognize.", Required: false, Disabled: false, Error: "", Size: nui.SizeDefault}, func(ft nui.Theme) {
nui.Input(c.Key("input"), ft, &s.Value, nui.InputOptions{Placeholder: "Project name"})
})使用说明
这个示例为 Input 添加标签、帮助、必填标记和可编辑的错误说明。将回调收到的主题继续传给输入框,可保持父字段与子控件的状态一致。
API 参考
FormField
源码func FormField(c *ui.Context, t Theme, opts FormFieldOptions, content func(Theme)) ui.ElementFormFieldOptions
源码type FormFieldOptions struct {
// Name and Value register a serialized value with the enclosing Form.
Name, Value string
Label, Description, Help, Hint, Error string
Required, Disabled bool
Size Size
Orientation Optional[Orientation] // Defaults to Vertical.
Decoration
}| 字段 | 类型 | 说明 |
|---|---|---|
Name | stringGo 零值: | 表单字段或对象的名称。 |
Value | stringGo 零值: | 控件值、字段值或数据读取函数。 |
Label | stringGo 零值: | 控件标签或可访问名称。 |
Description | stringGo 零值: | 补充说明文字。 |
Help | stringGo 零值: | 字段下方的帮助文字。 |
Hint | stringGo 零值: | 字段的简短辅助提示。 |
Error | stringGo 零值: | 错误状态或错误说明。 |
Required | boolGo 零值: | 将字段标记为必填。 |
Disabled | boolGo 零值: | 禁用组件及其交互。 |
Size | SizeGo 零值: | 组件尺寸;默认值继承主题或组件尺寸。 |
Orientation | Optional[Orientation]Go 零值: | 水平或垂直方向;未设置时使用组件默认方向。 |
UI | StylesGo 零值: | 以部件名称为键覆盖外观和间距。 |
Style | func(Slot, ui.Element)Go 零值: | 同步配置当前构建的部件;不要保留 Element。 |