Documentation
¶
Index ¶
- func RenderInput(inp input.Input) *dom.Element
- func SetGlobalClass(classes ...string)
- type Form
- func (f *Form) Children() []dom.Component
- func (f *Form) Focus() *Form
- func (f *Form) FocusedFieldID() string
- func (f *Form) GetID() string
- func (f *Form) HideSubmit() *Form
- func (f *Form) Input(fieldName string) input.Input
- func (f *Form) IsDirty() bool
- func (f *Form) LoadValues(data model.Fielder) error
- func (f *Form) MarkPristine()
- 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 Option
- type Renderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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. opts is typically ShowField(...) to opt a primary key back into the render — see that function. 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) Focus ¶ added in v0.2.22
Focus moves keyboard focus to the form's first field — a host UI calls this when entering an editable state (e.g. crudview's "+" / ⋮ Editar) so the user can start typing immediately instead of having to click into the form. A no-op if the form has no fields. Imperative, not reactive: the form's DOM already exists by the time a host unlocks it (this never runs on first mount), so a direct dom.Get+Focus is enough — no binding needed.
func (*Form) FocusedFieldID ¶ added in v0.2.22
FocusedFieldID returns the id Focus() last targeted (empty if never called, or the form has no fields). Real focus movement is a WASM-only DOM side effect (a no-op in the backend/SSR stub); this makes the INTENT observable in any build, e.g. for the view/conformance "New/Edit focuses the first field" clause to assert against without a live DOM.
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) IsDirty ¶ added in v0.2.24
IsDirty reports whether any field's current value differs from the baseline captured at the last load/reset (New, LoadValues, Reset). A host uses this to gate persistence — e.g. crudview's auto-save on field commit — so moving focus through a field without changing it never triggers a write. Comparing valueSignals directly (not a struct diff) keeps this exact and dependency-free: the signals are already the form's single source of truth for "current value" everywhere else in this package.
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) MarkPristine ¶ added in v0.2.24
func (f *Form) MarkPristine()
MarkPristine re-snapshots the baseline to the form's CURRENT values. A host calls this right after a successful save so a later field commit, with nothing further changed since that save, is not considered dirty again.
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 Option ¶ added in v0.3.27
type Option func(*Form)
Option configures New. The only kind today is ShowField.
func ShowField ¶ added in v0.3.27
ShowField keeps the given primary-key field(s) in the rendered form despite New's default of hiding every PK (see the skip in New's loop) — an id is normally system-assigned and opaque, and an editable box for it invites a user to "fix" a value that isn't theirs to change. Use this for the rare PK that genuinely is user-facing (a vanity slug, a manually assigned code). A no-op for a name that isn't a PK — there is nothing to opt back INTO.
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).