Documentation
¶
Index ¶
- func RenderCSS() *css.Stylesheet
- func RenderInput(inp input.Input) *dom.Element
- func SetGlobalClass(classes ...string)
- type Form
- func (f *Form) Children() []dom.Component
- func (f *Form) GetID() string
- func (f *Form) HideSubmit() *Form
- func (f *Form) Input(fieldName string) input.Input
- func (f *Form) LoadValues(data model.Fielder) error
- func (f *Form) NoResetOnSuccess() *Form
- func (f *Form) OnFieldChange(fn func()) *Form
- func (f *Form) OnSubmit(fn func(model.Fielder, func(error))) *Form
- func (f *Form) ParentID() string
- func (f *Form) Render() *dom.Element
- func (f *Form) Reset()
- func (f *Form) SetClass(classes ...string) *Form
- func (f *Form) SetID(id string)
- func (f *Form) SetLocked(v bool) *Form
- func (f *Form) SetOptions(fieldName string, opts ...fmt.KeyValue) *Form
- func (f *Form) SetSSR(enabled bool) *Form
- func (f *Form) SetValues(fieldName string, values ...string) *Form
- func (f *Form) String() string
- func (f *Form) Submit() error
- func (f *Form) SubmitLabel(text string) *Form
- func (f *Form) SubmitLoadingLabel(text string) *Form
- func (f *Form) SyncValues(data model.Fielder) error
- func (f *Form) Validate() error
- func (f *Form) ValidateData(action byte, data model.Fielder) error
- type Namer
- type Renderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderCSS ¶ added in v0.2.4
func RenderCSS() *css.Stylesheet
RenderCSS returns the form's CSS contribution (additive — see tinywasm/css contract). Call from the project's css.go aggregate so assetmin picks it up.
func RenderInput ¶ added in v0.2.7
RenderInput is kept for backward compatibility and as a standalone helper
func SetGlobalClass ¶ added in v0.0.2
func SetGlobalClass(classes ...string)
Types ¶
type Form ¶
Form represents a form instance.
func New ¶
New creates a new Form from a Fielder. parentID: ID of the parent DOM element where the form will be mounted. Returns an error if any exported field has no matching registered input.
func (*Form) Children ¶ added in v0.2.1
Children returns the form's input fields as dom components (O(1), zero-alloc).
func (*Form) HideSubmit ¶ added in v0.2.3
HideSubmit disables rendering of the submit button. Use this when the form is part of a larger UI that provides its own submit control (e.g. an external toolbar). Default is to render one.
func (*Form) Input ¶ added in v0.0.2
Input returns the input with the given field name, or nil if not found.
func (*Form) LoadValues ¶ added in v0.2.14
LoadValues populates every input from data, the inverse of SyncValues. It is the operation a CRUD view needs when the user selects a record: one call, no per-field string conversion at the call site.
A nil data (including a typed-nil pointer inside the interface) resets the form — that is the "new record" case, not an error.
func (*Form) NoResetOnSuccess ¶ added in v0.2.4
NoResetOnSuccess disables the automatic form reset after a successful submit.
func (*Form) OnFieldChange ¶ added in v0.2.20
OnFieldChange registers a callback fired every time a field is committed by the user: blur for text/textarea/datalist, change for select/radio. This is the hook a host uses for auto-save (no explicit Save button) — the callback runs AFTER the field's own value/validate update, so the form's data is current.
func (*Form) OnSubmit ¶ added in v0.0.2
OnSubmit sets the callback for form submission in WASM mode.
func (*Form) Reset ¶ added in v0.2.4
func (f *Form) Reset()
Reset clears all input values and error messages in the DOM and internal state.
func (*Form) SetClass ¶ added in v0.2.13
SetClass appends CSS classes to this form (on top of any global classes set via SetGlobalClass). Chainable.
func (*Form) SetLocked ¶ added in v0.2.20
SetLocked gates every field to read-only/disabled (whole-form, not per-field) without discarding their values — used by a host UI to show an existing record before an explicit "edit" action unlocks it. Reactive: takes effect immediately on an already-rendered form.
func (*Form) SetOptions ¶ added in v0.0.2
SetOptions sets options for the input matching the given field name.
func (*Form) SetValues ¶ added in v0.0.2
SetValues sets values for the input matching the given field name.
func (*Form) Submit ¶ added in v0.2.13
Submit runs the full submit pipeline programmatically: syncs input values into the bound struct, validates, and (if valid) fires the OnSubmit callback. Returns the first validation error, or nil if the submission was dispatched. The async result of the submission itself is delivered through the OnSubmit callback's done function.
func (*Form) SubmitLabel ¶ added in v0.2.3
SubmitLabel customizes the text on the submit button. If never called, the button shows "Submit".
func (*Form) SubmitLoadingLabel ¶ added in v0.2.4
SubmitLoadingLabel customizes the text on the submit button while submitting.
func (*Form) SyncValues ¶ added in v0.0.2
SyncValues copies all input values back into the bound struct via the Fielder's Pointers() method.
type Namer ¶ added in v0.0.29
type Namer interface {
FormName() string
}
Namer is optionally implemented by Fielder types to provide a custom name. If not implemented, the form derives the name from the first Schema field's context.
type Renderer ¶ added in v0.2.13
type Renderer interface {
RenderInput(value *dom.SignalString, onInput func(string)) *dom.Element
}
Renderer is an optional capability for custom inputs that own their markup. The form still owns the field wrapper (div.tw-field), the error span, and validation: the widget must call onInput with the new value on user input — the form updates the value signal and runs live validation. The value signal carries the initial value and programmatic updates (SetValues).