Documentation
¶
Overview ¶
Package ui contains the standard JaWS widget implementations.
The package is intentionally organized around extension-oriented building blocks so new widgets can be authored here without reading JaWS core code:
- HTMLInner: base renderer for tags with inner HTML content.
- Input, InputText, InputBool, InputFloat, InputDate: typed input helpers that handle event/update flow.
- ContainerHelper: helper for widgets that render dynamic child UI lists.
Naming follows short widget names (`Span`, `NewSpan`).
HTML-inner widgets route content through bind.MakeHTMLGetter. Plain strings are treated as trusted HTML, while bind.Getter[string], bind.Binder[string] and fmt.Stringer values are escaped. Raw template.HTMLAttr params are also trusted and written as attributes as-is. Use getter/stringer forms or html/template escaping for untrusted user text.
Index ¶
- Variables
- func Clickable(innerHTML any, onClick func(elem *jaws.Element, click jaws.Click) (err error)) jaws.ClickHandlerdeprecated
- func Handler(jw *jaws.Jaws, name string, dot any) http.Handler
- type A
- type Button
- type Checkbox
- type Container
- type ContainerHelper
- type Date
- type Div
- type HTMLInner
- type Img
- type Input
- type InputBool
- type InputDate
- type InputFloat
- type InputText
- type IsJsVar
- type JsVar
- func (jsvar *JsVar[T]) JawsGet(elem *jaws.Element) (value T)
- func (jsvar *JsVar[T]) JawsGetPath(elem *jaws.Element, jsPath string) (value any)
- func (jsvar *JsVar[T]) JawsGetTag(tag.Context) any
- func (jsvar *JsVar[T]) JawsInput(elem *jaws.Element, value string) (err error)
- func (jsvar *JsVar[T]) JawsRender(elem *jaws.Element, w io.Writer, params []any) (err error)
- func (jsvar *JsVar[T]) JawsSet(elem *jaws.Element, value T) (err error)
- func (jsvar *JsVar[T]) JawsSetPath(elem *jaws.Element, jsPath string, value any) (err error)
- func (jsvar *JsVar[T]) JawsUpdate(elem *jaws.Element)
- type JsVarMaker
- type Label
- type Li
- type Number
- type Object
- type ObjectClickedHook
- type ObjectContextMenuHook
- type ObjectInitialHTMLAttrHook
- type Option
- type Password
- type PathSetter
- type Radio
- type RadioElement
- type Range
- type Register
- type RequestWriter
- func (rw RequestWriter) A(innerHTML any, params ...any) error
- func (rw RequestWriter) Button(innerHTML any, params ...any) error
- func (rw RequestWriter) Checkbox(value any, params ...any) error
- func (rw RequestWriter) Container(outerHTMLTag string, c jaws.Container, params ...any) error
- func (rw RequestWriter) Date(value any, params ...any) error
- func (rw RequestWriter) Div(innerHTML any, params ...any) error
- func (rw RequestWriter) Get(key string) (value any)
- func (rw RequestWriter) HeadHTML() error
- func (rw RequestWriter) Img(imageSrc any, params ...any) error
- func (rw RequestWriter) Initial() *http.Request
- func (rw RequestWriter) JsVar(jsvarName string, jsvar any, params ...any) (err error)
- func (rw RequestWriter) Label(innerHTML any, params ...any) error
- func (rw RequestWriter) Li(innerHTML any, params ...any) error
- func (rw RequestWriter) NewUI(ui jaws.UI, params ...any) (err error)
- func (rw RequestWriter) Number(value any, params ...any) error
- func (rw RequestWriter) Password(value any, params ...any) error
- func (rw RequestWriter) Radio(value any, params ...any) error
- func (rw RequestWriter) RadioGroup(nba *named.BoolArray) (rel []RadioElement)
- func (rw RequestWriter) Range(value any, params ...any) error
- func (rw RequestWriter) Register(updater jaws.Updater, params ...any) jid.Jid
- func (rw RequestWriter) Select(sh named.SelectHandler, params ...any) error
- func (rw RequestWriter) Session() *jaws.Session
- func (rw RequestWriter) Set(key string, value any)
- func (rw RequestWriter) Span(innerHTML any, params ...any) error
- func (rw RequestWriter) TailHTML() error
- func (rw RequestWriter) Tbody(c jaws.Container, params ...any) error
- func (rw RequestWriter) Td(innerHTML any, params ...any) error
- func (rw RequestWriter) Template(outerHTMLTag, name string, dot any, params ...any) error
- func (rw RequestWriter) Text(value any, params ...any) error
- func (rw RequestWriter) Textarea(value any, params ...any) error
- func (rw RequestWriter) Tr(innerHTML any, params ...any) error
- func (rw RequestWriter) Write(p []byte) (n int, err error)
- type Select
- type SetPather
- type Span
- type Tbody
- type Td
- type Template
- func (tmpl Template) JawsClick(elem *jaws.Element, click jaws.Click) (err error)
- func (tmpl Template) JawsContextMenu(elem *jaws.Element, click jaws.Click) (err error)
- func (tmpl Template) JawsInput(elem *jaws.Element, value string) (err error)
- func (tmpl Template) JawsRender(elem *jaws.Element, w io.Writer, params []any) (err error)
- func (tmpl Template) JawsUpdate(elem *jaws.Element)
- func (tmpl Template) String() string
- type Text
- type Textarea
- type Tr
- type With
Constants ¶
This section is empty.
Variables ¶
var ErrIllegalJsVarName errIllegalJsVarName
ErrIllegalJsVarName is returned when a JsVar name is missing, not a string, or does not follow valid top-level identifier syntax.
var ErrIllegalJsVarPath = errors.New("jsvar: path contains illegal framing byte (tab, newline or carriage return)")
ErrIllegalJsVarPath reports that a JsVar path contained a byte significant to the WebSocket wire framing (a tab, newline or carriage return).
A JsVar path is written verbatim into a what.Set frame (only the value side is JSON-encoded), and the client splits frames on '\n' and fields on '\t'. A path carrying those bytes could corrupt the frame or inject fabricated orders into peer browsers sharing the JsVar, so JsVar.JawsSetPath (and incoming browser writes via JsVar.JawsInput) reject it before applying or broadcasting. The raw path is deliberately not echoed in the message to avoid log injection.
var ErrJsVarArgumentType = errors.New("expected jaws.UI or JsVarMaker")
ErrJsVarArgumentType is returned when RequestWriter.JsVar receives an argument that is neither a JaWS UI nor a JsVarMaker.
var ErrJsVarTooLarge = errors.New("jsvar: serialized value exceeds MaxClientJsVarBytes")
ErrJsVarTooLarge reports that a client-writable JsVar grew past MaxClientJsVarBytes.
It is returned by JsVar.JawsRender when the serialized size of a JsVar that does not implement PathSetter exceeds the cap; the jaws.Request is aborted. See the JsVar SECURITY note.
var ErrMissingTemplate errMissingTemplate
ErrMissingTemplate is returned when trying to render an undefined template by name.
var MaxClientJsVarBytes = 1 << 20 // 1 MiB
MaxClientJsVarBytes bounds the JSON-serialized size of a client-writable JsVar whose bound value does not implement PathSetter.
Set it before serving requests; a value <= 0 disables the cap. Values that implement PathSetter enforce their own bounds and are exempt.
Such a JsVar is written by the generic path setter, which a hostile browser could use to grow server-side state without bound across many writes (each individual write is already bounded by the WebSocket read limit). When the value is serialized for the browser in JsVar.JawsRender, a value larger than this many bytes aborts the jaws.Request (ErrJsVarTooLarge); the bound value is never marshaled solely to measure it, which would turn an append flood into O(n^2) work.
Functions ¶
func Clickable
deprecated
added in
v0.304.0
func Clickable(innerHTML any, onClick func(elem *jaws.Element, click jaws.Click) (err error)) jaws.ClickHandler
Clickable returns an object implementing bind.HTMLGetter, jaws.ClickHandler and tag.TagGetter.
innerHTML is passed to bind.MakeHTMLGetter, which may or may not provide tags.
Deprecated: use New(innerHTML).Clicked(...) directly.
func Handler ¶
Handler returns an http.Handler that renders the named template.
The returned handler can be registered directly with a router. Each request results in the template being looked up through the configured template lookupers and rendered with a With value as the template data, exposing dot through its Dot field.
Types ¶
type A ¶
type A struct{ HTMLInner }
A renders an HTML anchor element with dynamic inner HTML.
func NewA ¶
NewA returns an anchor widget whose inner HTML is rendered from innerHTML. innerHTML is passed to bind.MakeHTMLGetter; plain strings are trusted HTML.
type Button ¶
type Button struct{ HTMLInner }
Button renders an HTML button element with dynamic inner HTML.
func NewButton ¶
NewButton returns a button widget whose inner HTML is rendered from innerHTML. innerHTML is passed to bind.MakeHTMLGetter; plain strings are trusted HTML.
type Checkbox ¶
type Checkbox struct{ InputBool }
Checkbox renders an HTML checkbox input bound to a bool setter.
func NewCheckbox ¶
NewCheckbox returns a checkbox input widget bound to g.
type Container ¶
type Container struct {
OuterHTMLTag string
ContainerHelper
}
Container renders an HTML element around a dynamic child collection.
func NewContainer ¶
NewContainer returns a container widget that renders c inside outerHTMLTag. The returned widget tracks child elements and updates them using ContainerHelper.
func (*Container) JawsRender ¶
JawsRender renders ui as its configured container element.
func (*Container) JawsUpdate ¶
JawsUpdate updates the child collection.
type ContainerHelper ¶
ContainerHelper is a helper for widgets that render dynamic child collections.
It tracks previously rendered child elements and performs append/remove/order updates during ContainerHelper.UpdateContainer.
A ContainerHelper belongs to a widget instance and is intended for render-scoped widget lifetimes (for example widgets created via RequestWriter helper methods).
Error model: Child render/update failures are treated as application bugs. Initial-render errors are returned to the caller, and update-time append render errors are reported through MustLog (which may panic when no logger is configured). After such failures, DOM and request-tracked element state may be partially updated and therefore inconsistent until the next full render/reload.
func NewContainerHelper ¶
func NewContainerHelper(c jaws.Container) ContainerHelper
NewContainerHelper returns a ContainerHelper for rendering and updating c. ContainerHelper values are render-scoped and should not be reused across requests.
func (*ContainerHelper) RenderContainer ¶
func (u *ContainerHelper) RenderContainer(elem *jaws.Element, w io.Writer, outerHTMLTag string, params []any) (err error)
RenderContainer renders outerHTMLTag around the current children from jaws.Container.JawsContains.
func (*ContainerHelper) UpdateContainer ¶
func (u *ContainerHelper) UpdateContainer(elem *jaws.Element)
UpdateContainer updates child elements to match jaws.Container.JawsContains.
Render errors for newly appended children are reported through jaws.Jaws.MustLog, which may panic when no jaws.Jaws.Logger is configured.
type Date ¶
type Date struct{ InputDate }
Date renders an HTML date input bound to a time value setter.
type Div ¶
type Div struct{ HTMLInner }
Div renders an HTML div element with dynamic inner HTML.
func NewDiv ¶
NewDiv returns a div widget whose inner HTML is rendered from innerHTML. innerHTML is passed to bind.MakeHTMLGetter; plain strings are trusted HTML.
type HTMLInner ¶
type HTMLInner struct {
// HTMLGetter returns the trusted inner HTML to render and update.
HTMLGetter bind.HTMLGetter
}
HTMLInner is a reusable base for widgets that render as `<tag>inner</tag>`.
func (*HTMLInner) JawsUpdate ¶
JawsUpdate updates the rendered inner HTML.
type Img ¶
Img renders an HTML img element whose src is read from a string getter.
func (*Img) JawsRender ¶
JawsRender renders ui as an HTML img element.
func (*Img) JawsUpdate ¶
JawsUpdate updates the src attribute.
type Input ¶
type Input struct {
Last atomic.Value // the last value received from the request
// contains filtered or unexported fields
}
Input stores common state for interactive input widgets. There is one of these per request and input widget.
type InputBool ¶
InputBool is the reusable base for boolean input widgets.
func (*InputBool) JawsUpdate ¶
JawsUpdate updates the input value when the bound bool value changes.
type InputDate ¶
InputDate is the reusable base for date input widgets.
func (*InputDate) JawsUpdate ¶
JawsUpdate updates the input value when the bound date value changes.
type InputFloat ¶
InputFloat is the reusable base for float64 input widgets.
func (*InputFloat) JawsInput ¶ added in v0.401.0
func (u *InputFloat) JawsInput(elem *jaws.Element, value string) (err error)
JawsInput stores a browser-side float64 input value.
func (*InputFloat) JawsUpdate ¶
func (u *InputFloat) JawsUpdate(elem *jaws.Element)
JawsUpdate updates the input value when the bound float64 value changes.
type InputText ¶
InputText is the reusable base for string input widgets.
func (*InputText) JawsUpdate ¶
JawsUpdate updates the input value when the bound string value changes.
type IsJsVar ¶
type IsJsVar interface {
bind.RWLocker
jaws.UI
jaws.InputHandler
PathSetter
}
IsJsVar is implemented by JaWS UI values that bind a Go value to a browser-side JavaScript variable.
type JsVar ¶
type JsVar[T any] struct { bind.RWLocker Ptr *T // bound Go value // contains filtered or unexported fields }
JsVar binds a Go value to a named JavaScript variable in the browser.
It is safe for concurrent use when the locker passed to NewJsVar is safe for concurrent use.
SECURITY: a JsVar is client-writable. Incoming browser "set" messages are applied by path to the bound value. If the bound value implements PathSetter its JawsSetPath validates and applies the change; otherwise the change is applied by the generic path setter (github.com/linkdata/jq.Set), which will set any json-tagged field and append to slices one element per message. The size of any single client write is bounded by the WebSocket read limit; to also stop a hostile client growing server state without bound across many writes, a non-PathSetter value whose serialized size exceeds MaxClientJsVarBytes aborts the jaws.Request when it is next rendered (ErrJsVarTooLarge). The cap does not prevent a client from setting individual json-tagged fields, so when only some fields/paths should be client-writable, implement PathSetter on the bound value to allow-list paths and bound lengths. See jawstree's Node for an example that restricts client writes to a single boolean field.
func NewJsVar ¶
NewJsVar creates a JsVar over v protected by l.
The locker l must be non-nil and must remain valid for the lifetime of the JsVar.
func (*JsVar[T]) JawsGetPath ¶
JawsGetPath returns the value at jsPath, logging lookup errors on elem when possible.
func (*JsVar[T]) JawsGetTag ¶
JawsGetTag returns the current dirty tag.
It is safe for concurrent use. The tag.Context argument is ignored and may be nil.
func (*JsVar[T]) JawsInput ¶ added in v0.401.0
JawsInput applies a browser-side JavaScript variable update.
There is no per-write size check here: the size of any single incoming message is already bounded by the WebSocket read limit set on the connection (see SetReadLimit in the request handler). Cumulative growth of a non-PathSetter value past MaxClientJsVarBytes is caught after the fact in JsVar.JawsRender, which avoids re-marshaling the bound value on every write (an append flood would otherwise be O(n^2)).
func (*JsVar[T]) JawsRender ¶
JawsRender writes the hidden element that seeds and routes the JavaScript variable.
The write lock is held only while deriving the dirty tag from the bound value (via jaws.Element.ApplyGetter) and marshaling it, so the marshaled Ptr stays consistent with that tag even if another request sharing this JsVar sets it concurrently. The lock is released before jaws.Element.ApplyParams and, crucially, before writing to w: holding the value lock across a network write would let a slow client stall every goroutine sharing the locker. While the lock is held the bound value's tag.TagGetter.JawsGetTag and jaws.InitHandler.JawsInit callbacks run, so they must not re-enter this JsVar (e.g. call JawsGet or JawsSet on it), which would self-deadlock the non-reentrant lock.
func (*JsVar[T]) JawsSetPath ¶
JawsSetPath sets the value at jsPath and broadcasts the change. It is a programmatic (server-side, trusted) write and is not size-capped at the write boundary; see MaxClientJsVarBytes for the browser-write cap.
func (*JsVar[T]) JawsUpdate ¶
JawsUpdate is a no-op because updates are broadcast by path setters.
type JsVarMaker ¶
JsVarMaker creates a request-scoped JavaScript variable binding.
type Label ¶
type Label struct{ HTMLInner }
Label renders an HTML label element with dynamic inner HTML.
func NewLabel ¶
NewLabel returns a label widget whose inner HTML is rendered from innerHTML. innerHTML is passed to bind.MakeHTMLGetter; plain strings are trusted HTML.
type Li ¶
type Li struct{ HTMLInner }
Li renders an HTML list item with dynamic inner HTML.
func NewLi ¶
NewLi returns a list item widget whose inner HTML is rendered from innerHTML. innerHTML is passed to bind.MakeHTMLGetter; plain strings are trusted HTML.
type Number ¶
type Number struct{ InputFloat }
Number renders an HTML number input bound to a float64 setter.
type Object ¶ added in v0.400.0
type Object interface {
bind.HTMLGetter
tag.TagGetter
jaws.ClickHandler
jaws.ContextMenuHandler
jaws.InitialHTMLAttrHandler
// Clicked returns an [Object] that will call fn when [jaws.ClickHandler.JawsClick] is invoked.
Clicked(fn ObjectClickedHook) (newobj Object)
// ContextMenu returns an [Object] that will call fn when
// [jaws.ContextMenuHandler.JawsContextMenu] is invoked.
ContextMenu(fn ObjectContextMenuHook) (newobj Object)
// InitialHTMLAttr returns an [Object] that will call fn when
// [jaws.InitialHTMLAttrHandler.JawsInitialHTMLAttr] is invoked.
InitialHTMLAttr(fn ObjectInitialHTMLAttrHook) (newobj Object)
}
Object is a chainable UI object that combines HTML rendering, tags and optional event handlers.
type ObjectClickedHook ¶ added in v0.500.0
ObjectClickedHook is a function to call when a click event is received.
It is named distinctly from the generic bind.ClickedHook to avoid confusion: this one operates on an Object, not a bind.Binder.
type ObjectContextMenuHook ¶ added in v0.500.0
ObjectContextMenuHook is a function to call when a context menu event is received.
type ObjectInitialHTMLAttrHook ¶ added in v0.500.0
ObjectInitialHTMLAttrHook is a function to call when a jaws.Element is initially rendered.
type Option ¶
Option renders an HTML option element backed by a named.Bool.
func (Option) JawsRender ¶
JawsRender renders ui as an HTML option element. The markup is produced by named.RenderBoolOption, the single source of <option> markup, so it cannot diverge from the options named.BoolArray renders.
func (Option) JawsUpdate ¶
JawsUpdate updates the selected attribute.
type Password ¶
type Password struct{ InputText }
Password renders an HTML password input bound to a string setter.
func NewPassword ¶
NewPassword returns a password input widget bound to g.
type PathSetter ¶
type PathSetter interface {
// JawsSetPath should set the JSON object member identified by jsPath to the given value.
//
// If the member is already the given value, it should return [jaws.ErrValueUnchanged].
JawsSetPath(elem *jaws.Element, jsPath string, value any) (err error)
}
PathSetter can set a nested JSON path value.
type Radio ¶
type Radio struct{ InputBool }
Radio renders an HTML radio input bound to a bool setter.
type RadioElement ¶
type RadioElement struct {
// contains filtered or unexported fields
}
RadioElement renders the input and label elements for one radio option.
The underlying jaws.Element values are created lazily on the first call to RadioElement.Radio or RadioElement.Label, so options that a template never renders register no elements on the jaws.Request. Call each of Radio and Label at most once. Render Label only when Radio is also rendered: Label emits a for="..." referencing the radio's id, so a Label without its Radio points at an input that is absent from the document (and leaves an unrendered radio Element registered on the Request for the request's lifetime).
type Range ¶
type Range struct{ InputFloat }
Range renders an HTML range input bound to a float64 setter.
type Register ¶
Register is an update-only widget that renders no HTML; it exists so its embedded jaws.Updater receives dynamic updates.
func NewRegister ¶
NewRegister returns an update-only widget that invokes updater during updates.
type RequestWriter ¶
RequestWriter combines a jaws.Request with an io.Writer while rendering.
func (RequestWriter) A ¶
func (rw RequestWriter) A(innerHTML any, params ...any) error
A renders an HTML anchor element.
A plain string innerHTML is trusted HTML and is not escaped; see NewA and bind.MakeHTMLGetter for how to pass untrusted user input safely.
func (RequestWriter) Button ¶
func (rw RequestWriter) Button(innerHTML any, params ...any) error
Button renders an HTML button element.
A plain string innerHTML is trusted HTML and is not escaped; see NewButton and bind.MakeHTMLGetter for how to pass untrusted user input safely.
func (RequestWriter) Checkbox ¶
func (rw RequestWriter) Checkbox(value any, params ...any) error
Checkbox renders an HTML checkbox input.
func (RequestWriter) Date ¶
func (rw RequestWriter) Date(value any, params ...any) error
Date renders an HTML date input.
func (RequestWriter) Div ¶
func (rw RequestWriter) Div(innerHTML any, params ...any) error
Div renders an HTML div element.
A plain string innerHTML is trusted HTML and is not escaped; see NewDiv and bind.MakeHTMLGetter for how to pass untrusted user input safely.
func (RequestWriter) Get ¶
func (rw RequestWriter) Get(key string) (value any)
Get calls jaws.Request.Get.
func (RequestWriter) HeadHTML ¶
func (rw RequestWriter) HeadHTML() error
HeadHTML outputs the HTML code needed in the head section.
func (RequestWriter) Img ¶
func (rw RequestWriter) Img(imageSrc any, params ...any) error
Img renders an HTML img element.
func (RequestWriter) Initial ¶
func (rw RequestWriter) Initial() *http.Request
Initial returns the initial http.Request.
func (RequestWriter) JsVar ¶
func (rw RequestWriter) JsVar(jsvarName string, jsvar any, params ...any) (err error)
JsVar binds a JsVar to a named JavaScript variable.
You can also pass a JsVarMaker instead of a JsVar.
func (RequestWriter) Label ¶
func (rw RequestWriter) Label(innerHTML any, params ...any) error
Label renders an HTML label element.
A plain string innerHTML is trusted HTML and is not escaped; see NewLabel and bind.MakeHTMLGetter for how to pass untrusted user input safely.
func (RequestWriter) Li ¶
func (rw RequestWriter) Li(innerHTML any, params ...any) error
Li renders an HTML list item.
A plain string innerHTML is trusted HTML and is not escaped; see NewLi and bind.MakeHTMLGetter for how to pass untrusted user input safely.
func (RequestWriter) NewUI ¶ added in v0.500.0
func (rw RequestWriter) NewUI(ui jaws.UI, params ...any) (err error)
NewUI creates an element for ui and renders it to the underlying writer.
func (RequestWriter) Number ¶
func (rw RequestWriter) Number(value any, params ...any) error
Number renders an HTML number input.
func (RequestWriter) Password ¶
func (rw RequestWriter) Password(value any, params ...any) error
Password renders an HTML password input.
func (RequestWriter) Radio ¶
func (rw RequestWriter) Radio(value any, params ...any) error
Radio renders an HTML radio input.
func (RequestWriter) RadioGroup ¶
func (rw RequestWriter) RadioGroup(nba *named.BoolArray) (rel []RadioElement)
RadioGroup returns a RadioElement for each value in nba. Elements are created lazily as they are rendered; see RadioElement.
func (RequestWriter) Range ¶
func (rw RequestWriter) Range(value any, params ...any) error
Range renders an HTML range input.
func (RequestWriter) Register ¶
Register creates a new Element with the given Updater as a tag for dynamic updates. Additional tags may be provided in params. The updater's jaws.Updater.JawsUpdate method will be called immediately to ensure the initial rendering is correct.
Returns a jid.Jid, suitable for including as an HTML id attribute:
<div id="{{$.Register .MyUpdater}}">...</div>
func (RequestWriter) Select ¶
func (rw RequestWriter) Select(sh named.SelectHandler, params ...any) error
Select renders an HTML select element.
func (RequestWriter) Session ¶
func (rw RequestWriter) Session() *jaws.Session
Session returns the request's jaws.Session, or nil.
func (RequestWriter) Set ¶
func (rw RequestWriter) Set(key string, value any)
Set calls jaws.Request.Set.
func (RequestWriter) Span ¶
func (rw RequestWriter) Span(innerHTML any, params ...any) error
Span renders an HTML span element.
A plain string innerHTML is trusted HTML and is not escaped; see NewSpan and bind.MakeHTMLGetter for how to pass untrusted user input safely.
func (RequestWriter) TailHTML ¶
func (rw RequestWriter) TailHTML() error
TailHTML writes optional HTML code at the end of the page's BODY section that will immediately apply updates made during initial rendering.
func (RequestWriter) Tbody ¶
func (rw RequestWriter) Tbody(c jaws.Container, params ...any) error
Tbody renders an HTML tbody element.
func (RequestWriter) Td ¶
func (rw RequestWriter) Td(innerHTML any, params ...any) error
Td renders an HTML table cell.
A plain string innerHTML is trusted HTML and is not escaped; see NewTd and bind.MakeHTMLGetter for how to pass untrusted user input safely.
func (RequestWriter) Template ¶
func (rw RequestWriter) Template(outerHTMLTag, name string, dot any, params ...any) error
Template renders the given template using With as data.
The Dot field in With is set to dot, and name is resolved to a template.Template using jaws.Jaws.LookupTemplate. Template output is wrapped in a generated outerHTMLTag element that owns the JaWS ID and any HTML attrs passed in params. If outerHTMLTag is empty, no wrapper is emitted and HTML attr params have no generated element to apply to. The template must be a partial, not a full HTML document.
func (RequestWriter) Text ¶
func (rw RequestWriter) Text(value any, params ...any) error
Text renders an HTML text input.
func (RequestWriter) Textarea ¶
func (rw RequestWriter) Textarea(value any, params ...any) error
Textarea renders an HTML textarea.
func (RequestWriter) Tr ¶
func (rw RequestWriter) Tr(innerHTML any, params ...any) error
Tr renders an HTML table row.
A plain string innerHTML is trusted HTML and is not escaped; see NewTr and bind.MakeHTMLGetter for how to pass untrusted user input safely.
type Select ¶
type Select struct {
ContainerHelper
}
Select renders an HTML select element backed by a named.SelectHandler.
func NewSelect ¶
func NewSelect(sh named.SelectHandler) *Select
NewSelect returns a select widget backed by sh.
func (*Select) JawsInput ¶ added in v0.401.0
JawsInput stores a browser-side select value.
The input is ignored (returning a nil error) when the Container is not a bind.Setter of string.
func (*Select) JawsRender ¶
JawsRender renders ui as an HTML select element.
func (*Select) JawsUpdate ¶
JawsUpdate updates the selected value and child options.
The selected value is only updated when the Container is a bind.Setter of string; the child options are always updated.
type SetPather ¶
type SetPather interface {
// JawsPathSet notifies that a JSON object member identified by jsPath has been set
// to the given value and the change has been queued for broadcast.
JawsPathSet(elem *jaws.Element, jsPath string, value any)
}
SetPather is notified after a nested JSON path value has been set and broadcast.
type Span ¶
type Span struct{ HTMLInner }
Span renders an HTML span element with dynamic inner HTML.
func NewSpan ¶
NewSpan returns a span widget whose inner HTML is rendered from innerHTML. innerHTML is passed to bind.MakeHTMLGetter; plain strings are trusted HTML.
type Tbody ¶
type Tbody struct {
ContainerHelper
}
Tbody renders an HTML tbody containing dynamic child rows.
func (*Tbody) JawsRender ¶
JawsRender renders ui as an HTML tbody element.
func (*Tbody) JawsUpdate ¶
JawsUpdate updates the child rows.
type Td ¶
type Td struct{ HTMLInner }
Td renders an HTML table cell with dynamic inner HTML.
func NewTd ¶
NewTd returns a table cell widget whose inner HTML is rendered from innerHTML. innerHTML is passed to bind.MakeHTMLGetter; plain strings are trusted HTML.
type Template ¶
type Template struct {
OuterHTMLTag string // Optional wrapper tag for partial templates, for example "div" or "tr"; empty renders unwrapped.
Name string // Template name to be looked up using Jaws.LookupTemplate.
Dot any // Dot value to place in With.
}
Template references a Go html/template template to be rendered through JaWS.
The OuterHTMLTag field identifies the generated wrapper element used for partial templates. If OuterHTMLTag is empty, the template is rendered without a generated wrapper. Name identifies the template to execute and Dot contains the data exposed to the template through the With structure constructed during rendering. Wrapped templates receive the JaWS ID and any HTML attributes supplied at render time through the RequestWriter.Template helper. The referenced template must be a partial template, not a full HTML document.
func NewTemplate ¶
NewTemplate returns a Template UI value for rendering the named partial template with dot available as [With.Dot].
The template name is resolved when the value is rendered or updated, using the request's jaws.Jaws.LookupTemplate. If outerHTMLTag is non-empty, rendering wraps the template output in that generated element; the wrapper owns the JaWS ID and render-time HTML attributes. If outerHTMLTag is empty, rendering emits only the template output and Template.JawsUpdate has no wrapper to update.
Dot participates in tag expansion for dirty targeting and receives delegated click, context-menu, and input events when it implements the corresponding JaWS handler interfaces.
func (Template) JawsClick ¶ added in v0.401.0
JawsClick delegates click events to t.Dot when it implements jaws.ClickHandler.
func (Template) JawsContextMenu ¶ added in v0.401.0
JawsContextMenu delegates context-menu events to t.Dot when it implements jaws.ContextMenuHandler.
func (Template) JawsInput ¶ added in v0.401.0
JawsInput delegates input events to t.Dot when it implements jaws.InputHandler.
func (Template) JawsRender ¶
JawsRender renders t through the request's configured template lookupers.
func (Template) JawsUpdate ¶
JawsUpdate re-renders t into the template wrapper.
Unwrapped templates have no generated DOM element to update, so updates are ignored. Nested JaWS UI rendered by the template can still update through its own elements.
Lookup or execution errors are reported through jaws.Request.MustLog, which may panic when no jaws.Jaws.Logger is configured.
type Text ¶
type Text struct{ InputText }
Text renders an HTML text input bound to a string setter.
type Textarea ¶
type Textarea struct{ InputText }
Textarea renders an HTML textarea bound to a string setter.
func NewTextarea ¶
NewTextarea returns a textarea widget bound to g.
type Tr ¶
type Tr struct{ HTMLInner }
Tr renders an HTML table row with dynamic inner HTML.
func NewTr ¶
NewTr returns a table row widget whose inner HTML is rendered from innerHTML. innerHTML is passed to bind.MakeHTMLGetter; plain strings are trusted HTML.
type With ¶
type With struct {
*jaws.Element // the Element being rendered using a template
RequestWriter // the RequestWriter for nested UI helpers
Dot any // user data parameter
// Auth is the authentication information from [jaws.Jaws.MakeAuth]. When
// MakeAuth is nil it is a [jaws.DefaultAuth], whose IsAdmin returns true for
// everyone — gating UI on {{if .Auth.IsAdmin}} is only safe once MakeAuth is
// set. See [jaws.DefaultAuth] for the fail-open caveat.
Auth jaws.Auth
}
With is passed as the data parameter when using RequestWriter.Template, populated with all required members set.
Source Files
¶
- a.go
- button.go
- checkbox.go
- clickable.go
- common.go
- container.go
- containerhelper.go
- date.go
- div.go
- doc.go
- errjsvar.go
- errmissingtemplate.go
- handler.go
- html_widgets.go
- img.go
- input_widgets.go
- jsvar.go
- label.go
- li.go
- number.go
- object.go
- option.go
- password.go
- radio.go
- radiogroup.go
- range.go
- register.go
- requestwriter.go
- select.go
- span.go
- tbody.go
- td.go
- template.go
- text.go
- textarea.go
- tr.go
- with.go