Fast form generation from Go structs for TinyGo + WASM. Uses fmt.Fielder interface for zero-reflection data binding.
// User struct implements fmt.Fielder (usually generated by ormc)
f, err := form.New("parent-id", &User{Name: "John"})
html := f.RenderHTML() // render to HTML stringCreates a Form from a Fielder.
- Uses
data.Schema()to build inputs. - Matches each field to a registered
Inputby name/alias orField.Input. - Copies
data.Values()into inputs. - Form
id=parentID + "." + data.FormName().
Registers custom input types globally.
| Method | Description |
|---|---|
GetID() string |
Returns form's HTML id |
SetSSR(bool) *Form |
Enables SSR mode |
RenderHTML() string |
Generates form HTML |
Validate() error |
Validates all inputs |
SyncValues(fmt.Fielder) error |
Copies input values back into the provided data |
ValidateData(byte, fmt.Fielder) error |
Validates data (crudp.DataValidator) |
OnSubmit(func(fmt.Fielder) error) *Form |
Sets WASM submit callback |
OnMount() |
WASM only — sets up event delegation |
Input(fieldName string) input.Input |
Returns input for a field name |
If you were using form.New(parentID, &MyStruct{}), you must now ensure MyStruct implements fmt.Fielder. This is typically handled by tinywasm/orm's ormc tool.
API changes:
SyncValues()→SyncValues(data)OnSubmit(func(any) error)→OnSubmit(func(fmt.Fielder) error)ValidateData(action, ...any)→ValidateData(action, fmt.Fielder)
Tags are now parsed at generation time by ormc.
| Tag | Format | Description |
|---|---|---|
form |
"email" |
Force input type |
form |
"-" |
Exclude from form |
options |
"k:v" |
Select options |
validate |
"false" |
Skip validation |