Form Builder Engine (pkg/forms)
Layout Containers#
res.Form(func(form *forms.Form) *forms.Form {
return form.Schema(
// 1. Multi-Step Form Wizard
forms.Wizard(
forms.WizardStep("General Information").
Description("Basic product attributes").
Schema(
forms.Grid(2).Schema(
forms.TextInput("title").
Label("Product Title").
Required().
MaxLength(150),
forms.TextInput("sku").
Label("SKU Code").
Required().
Placeholder("PROD-XXXX"),
),
forms.Textarea("description").
Rows(4).
MaxLength(1000),
),
forms.WizardStep("Pricing & Inventory").
Description("Commercial configuration").
Schema(
forms.Grid(3).Schema(
forms.TextInput("price").
Numeric().
Prefix("$").
Required(),
forms.TextInput("cost_price").
Numeric().
Prefix("$"),
forms.TextInput("stock").
Numeric().
Default(0),
),
forms.Toggle("is_published").
Label("Publish immediately to storefront").
Default(true),
),
forms.WizardStep("Media & Repeater").
Description("Images and specifications").
Schema(
forms.ImageUpload("thumbnail").
Directory("products/thumbnails").
MaxFiles(1),
// Dynamic Nested Array Repeater
forms.Repeater("specifications").
Label("Technical Specifications").
Schema(
forms.TextInput("spec_key").Placeholder("e.g. Dimensions"),
forms.TextInput("spec_value").Placeholder("e.g. 10x20x5 cm"),
),
),
),
)
})
Other available layout containers include:
forms.Section(heading).Description(desc).Collapsible().Schema(...)forms.Grid(columns).Schema(...)forms.Tabs(forms.Tab("Details", ...), forms.Tab("SEO", ...))forms.Fieldset(legend).Schema(...)forms.Split(leftCol, rightCol)
Input Fields Reference#
| Constructor | Methods | Description |
|---|---|---|
forms.TextInput(name) | .Email(), .Password(), .Numeric(), .Tel(), .URL(), .Prefix("$"), .Suffix("/mo"), .Placeholder(...), .Required(), .Min(n), .Max(n) | Versatile text field with input mask formats |
forms.Textarea(name) | .Rows(n), .Cols(n), .MaxLength(n), .Placeholder(...) | Multi-line text field |
forms.Select(name) | .Options(map[string]string), .Searchable(), .Multiple() | Single or multi-select dropdown |
forms.Toggle(name) | .OnColor("success"), .OffColor("gray"), .Default(bool) | Boolean toggle switch |
forms.Checkbox(name) | .Label(...), .Default(bool) | Single checkbox |
forms.CheckboxList(name) | .Options(map[string]string) | Group of checkboxes |
forms.Radio(name) | .Options(map[string]string) | Radio button group |
forms.DatePicker(name) | .Format("2006-01-02"), .MinDate(...), .MaxDate(...) | Date selection |
forms.DateTimePicker(name) | .Format("2006-01-02 15:04:05") | Date and time picker |
forms.TimePicker(name) | .Format("15:04") | Time selection |
forms.FileUpload(name) | .Disk("s3"), .Directory("path"), .MaxFiles(n), .AcceptedFileTypes(...) | Secure file upload |
forms.ImageUpload(name) | Same as FileUpload + image preview cropping | Image upload |
forms.RichEditor(name) | .ToolbarButtons(...) | WYSIWYG HTML rich text editor |
forms.MarkdownEditor(name) | .PreviewMode() | Markdown editor with split preview |
forms.TagsInput(name) | .Separator(","), .Suggestions(...) | Tag list input |
forms.ColorPicker(name) | .Format("hex") | Hex/RGB color selector |
forms.KeyValue(name) | .KeyLabel(...), .ValueLabel(...) | Key-value dictionary editor |
forms.CodeEditor(name) | .Language("json") | Monospace code editor with syntax highlighting |
forms.Hidden(name) | .Default(val) | Hidden input field |
Live Reactivity & Dynamic Micro-Swaps#
Fields can react in real time without a full page refresh:
forms.Select("discount_type").
Options(map[string]string{
"percentage": "Percentage Discount (%)",
"fixed": "Fixed Amount ($)",
}).
Live(). // Triggers HTMX micro-swap on change
AfterStateUpdated(func(state any, form *forms.Form) {
if state == "percentage" {
// Modify form fields dynamically
}
})