named

package
v0.500.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package named provides named boolean values and collections used by select, option and radio widgets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderBoolOption added in v0.500.0

func RenderBoolOption(elem *jaws.Element, w io.Writer, nb *Bool, params []any) error

RenderBoolOption renders nb as an HTML <option> element into w. It is the single source of <option> markup shared by BoolArray's options and by ui.Option, so attribute/escaping behavior cannot drift between them.

func UpdateBoolOption added in v0.500.0

func UpdateBoolOption(elem *jaws.Element, nb *Bool)

UpdateBoolOption updates a rendered <option>'s selected attribute to match nb. It is the single source of the option's update behavior.

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool stores a named boolean value with an HTML representation.

Bool values are safe for concurrent use.

func NewBool

func NewBool(nba *BoolArray, name string, html template.HTML, checked bool) *Bool

NewBool returns a Bool with the given name, HTML and checked state.

The html argument is rendered as trusted HTML (it is the label shown in select lists and checkboxes) and is not escaped. When it is derived from untrusted user input it must be pre-escaped, e.g. template.HTML(template.HTMLEscapeString(s)).

If nba is non-nil, changing the value through Bool.JawsSet may dirty the containing BoolArray and deselect sibling values in single-select mode.

func (*Bool) Array

func (nb *Bool) Array() *BoolArray

Array returns the BoolArray that owns nb, or nil.

func (*Bool) Checked

func (nb *Bool) Checked() (checked bool)

Checked reports whether nb is checked.

func (*Bool) HTML

func (nb *Bool) HTML() (h template.HTML)

HTML returns the trusted HTML label for nb.

func (*Bool) JawsGet

func (nb *Bool) JawsGet(elem *jaws.Element) (yes bool)

JawsGet returns whether nb is checked.

func (*Bool) JawsGetHTML

func (nb *Bool) JawsGetHTML(elem *jaws.Element) (h template.HTML)

JawsGetHTML returns the trusted HTML label for nb.

func (*Bool) JawsSet

func (nb *Bool) JawsSet(elem *jaws.Element, checked bool) (err error)

JawsSet sets the checked state and dirties the affected element tags.

Lock ordering invariant: when both locks are needed, the owning BoolArray's mutex is always acquired before the Bool's mutex (as done here and by the BoolArray methods, which lock nba.mu then call into Bool). Any new method must preserve this array-before-bool order to avoid deadlocks.

Note that the elem.Dirty calls below run while nba.mu is still held (via the deferred Unlock); Dirty takes the outermost jaws Jaws.mu. This is the deliberate value-tier reverse edge documented in the jaws package "Locking" section, and is safe only because no holder of Jaws.mu ever calls back into these methods.

func (*Bool) Name

func (nb *Bool) Name() (s string)

Name returns the form value name for nb.

func (*Bool) Set

func (nb *Bool) Set(checked bool) (changed bool)

Set changes the checked state and reports whether it changed.

Unlike Bool.JawsSet, Set does not dirty any elements and does not deselect siblings in single-select mode; it only changes this value. Single-select consistency (at most one checked value) is an invariant maintained by going through JawsSet, so prefer JawsSet for widget-driven updates.

func (*Bool) String

func (nb *Bool) String() string

String returns a string representation of the Bool suitable for debugging.

type BoolArray

type BoolArray struct {
	// contains filtered or unexported fields
}

BoolArray stores the data required to support HTML select elements and sets of HTML radio buttons. It is safe to use from multiple goroutines concurrently.

func NewBoolArray

func NewBoolArray(multi bool) *BoolArray

NewBoolArray returns an empty BoolArray.

If multi is false, setting one value clears other names in the array. If multi is true, multiple values may be checked at the same time.

func (*BoolArray) Add

func (nba *BoolArray) Add(name string, text template.HTML) *BoolArray

Add adds a Bool with the given name and trusted HTML text. Returns itself.

The text argument is rendered as trusted HTML and is not escaped; pre-escape it (e.g. template.HTML(template.HTMLEscapeString(s))) when it is derived from untrusted user input. See NewBool.

Note that while it is legal to have multiple Bool values with the same name because HTML allows it, it is usually not a good idea.

func (*BoolArray) Count

func (nba *BoolArray) Count(name string) (n int)

Count returns the number of Bool values in the set that have the given name.

func (*BoolArray) Get

func (nba *BoolArray) Get() (name string)

Get returns the name of the first Bool in the group that has its checked value set to true. Returns an empty string if none are true.

In case you can have more than one selected or you need to distinguish between a blank name and the fact that none are set to true, use BoolArray.ReadLocked to inspect the data directly.

func (*BoolArray) IsChecked

func (nba *BoolArray) IsChecked(name string) (state bool)

IsChecked returns true if any Bool in the set with the given name is checked. Returns false if the name is not found.

func (*BoolArray) JawsContains

func (nba *BoolArray) JawsContains(elem *jaws.Element) (contents []jaws.UI)

JawsContains returns the option widgets for a select backed by nba.

func (*BoolArray) JawsGet

func (nba *BoolArray) JawsGet(elem *jaws.Element) string

JawsGet returns the currently selected name.

func (*BoolArray) JawsSet

func (nba *BoolArray) JawsSet(elem *jaws.Element, name string) (err error)

JawsSet selects name and dirties the changed Bool values and nba itself.

This mirrors Bool.JawsSet: every Bool whose checked state changes is dirtied in addition to the array tag, so consumers that bind individual Bools (such as radio buttons) update, not only the cascading github.com/linkdata/jaws/lib/ui.Select widget that re-renders from the array tag.

func (*BoolArray) ReadLocked

func (nba *BoolArray) ReadLocked(fn func(nbl []*Bool))

ReadLocked calls fn with the BoolArray locked for reading.

fn must not call other BoolArray methods, which would re-acquire the same non-reentrant lock and deadlock; operate only on the provided slice. Calling methods on the *Bool elements is safe because they use a separate mutex taken in array-before-bool order.

func (*BoolArray) Set

func (nba *BoolArray) Set(name string, state bool) (changed bool)

Set sets the checked state for Bool values with the given name.

Matching is by name, so values are addressed as logical options rather than individually: every Bool sharing the name is set together, and in single-select mode the at-most-one-checked invariant holds per distinct name (selecting a name deselects all values with a different name, but leaves same-named siblings checked). If the given name matches no values in single-select mode, everything will be deselected.

func (*BoolArray) String

func (nba *BoolArray) String() string

String returns a string representation of the BoolArray suitable for debugging.

func (*BoolArray) WriteLocked

func (nba *BoolArray) WriteLocked(fn func(nbl []*Bool) []*Bool)

WriteLocked calls fn with the BoolArray locked for writing and replaces the internal []*Bool slice with the return value.

As with BoolArray.ReadLocked, fn must not call other BoolArray methods (it would deadlock); operate only on the provided slice and its *Bool elements.

type SelectHandler

type SelectHandler interface {
	jaws.Container
	bind.Setter[string]
}

SelectHandler is implemented by values that can both render options and store a selected option name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL