Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FieldContext ¶
type FieldContext struct {
// Name is the model field's Go name — also the base name a simple
// widget reads directly from the submitted form, and the stable prefix
// a multi-input widget derives its own input names from.
Name string
// Label is the field's display label (from Options.Labels, or a
// humanized default).
Label string
// HelpText is optional descriptive text for the field (from
// Options.HelpText); empty if unset.
HelpText string
// Value is the field's current value, formatted for display. Empty for
// a new (zero) instance.
Value string
// Checked is the field's current boolean value, for checkbox-shaped
// widgets.
Checked bool
// ReadOnly reports whether the field should render non-editably and
// ignore submitted form data entirely (Options.ReadOnly). A Widget set
// via Options.Widgets is never consulted for a ReadOnly field — the
// admin package renders a single generic read-only presentation
// instead, uniformly, regardless of which Widget the field would
// otherwise use.
ReadOnly bool
// SelectOptions lists every row of the related model as a value/label
// pair, populated only for a foreign key field whose related model is
// registered — nil otherwise.
SelectOptions []SelectOption
// RelatedCreateURL links to the related model's admin create page for
// foreign-key fields whose related model is also admin-registered.
// Empty means no quick-create affordance should render.
RelatedCreateURL string
// RelatedCreateLabel is the accessible label for RelatedCreateURL.
// Empty means widgets may fall back to their own default.
RelatedCreateLabel string
}
FieldContext carries what a Widget needs to render and parse one model field's create/edit form control. The same FieldContext is passed to both Render and Parse, so a widget can derive its own submitted form key(s) from Name identically on both sides — e.g. a multi-input widget might use Name+"_date" and Name+"_time" — rather than a render-time and parse-time convention drifting apart.
type FieldValues ¶
FieldValues is the whole submitted form, so a Widget's Parse can read more than one input for a single Go field (see FieldContext.Name).
type ModelRegistration ¶
ModelRegistration is the admin metadata for a registered model.
type Options ¶
type Options struct {
ListDisplay []string
Search []string
Ordering []string
// Label names one of this model's own fields to display whenever it is
// shown as a related object elsewhere (e.g. on a Post's admin page for
// a Post.AuthorID foreign key). Unset falls back to showing the raw
// primary key value — never a hard error.
Label string
// Labels overrides a field's humanized default display label, keyed by
// Go field name.
Labels map[string]string
// HelpText adds descriptive text below a field's form control, keyed by
// Go field name.
HelpText map[string]string
// ReadOnly lists fields that render non-editably in create/edit forms.
// On edit, a read-only field keeps its existing stored value regardless
// of submitted form data; on create, it stays at its Go zero value.
// Submitted data for a read-only field is always ignored, never parsed.
ReadOnly []string
// FieldOrder lists fields in the order they should render; fields not
// listed keep their existing default order after the ordered ones.
FieldOrder []string
// Widgets overrides how a field renders and parses in create/edit
// forms, keyed by Go field name. See Widget — best-effort, not a
// stable contract.
Widgets map[string]Widget
}
Options controls how a model appears in the admin.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores admin registrations by model name.
func NewRegistry ¶
NewRegistry returns an empty, ready-to-use admin Registry.
func (*Registry) Get ¶
func (r *Registry) Get(name string) (ModelRegistration, bool)
Get returns an admin registration by model name.
func (*Registry) Registrations ¶
func (r *Registry) Registrations() []ModelRegistration
Registrations returns every registered model in unspecified order.
type SelectOption ¶
SelectOption is one <option> in a foreign key field's <select>.
type Widget ¶
type Widget interface {
Render(f FieldContext) template.HTML
Parse(f FieldContext, form FieldValues, dest reflect.Value) error
}
Widget renders one model field's create/edit form control and parses its submitted value back into the Go field, replacing tanGO's default behavior for that field alone — nothing else about the form changes. tanGO's built-in field behaviors (a generic text/number/date-time input, a checkbox, a textarea, and the foreign-key select) are themselves Widgets, set via Options.Widgets like any custom one.
This interface, tanGO's built-in widgets, and Options' Widgets/Labels/ HelpText/ReadOnly/FieldOrder fields are best-effort, not a stable contract — see docs/limitations.md. A widget's Render output may include its own <link>/<script> tags for CSS/JS (served via its owning app's own embed.FS route, per the convention reusable apps already use for static assets); since there is no shared deduplication, that output must be idempotent — safe to emit once per rendered instance — because the same widget on multiple fields will render its tags more than once.