list

package
v0.31.10 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package list contains list-type controls. This includes select lists and hierarchical lists.

Index

Constants

View Source
const (
	OrderedListNumberTypeNumber      = "1" // default
	OrderedListNumberTypeUpperLetter = "A"
	OrderedListNumberTypeLowerLetter = "a"
	OrderedListNumberTypeUpperRoman  = "I"
	OrderedListNumberTypeLowerRoman  = "i"
)
View Source
const (
	// UnorderedListStyleDisc is the default list style for main items and is a bullet
	UnorderedListStyleDisc = "disc" // default
	// UnorderedListStyleCircle is the default list style for 2nd level items and is an open circle
	UnorderedListStyleCircle = "circle"
	// UnorderedListStyleSquare sets a square as the bullet
	UnorderedListStyleSquare = "square"
	// UnorderedListStyleNone removes the bullet from the list
	UnorderedListStyleNone = "none"
)

Variables

This section is empty.

Functions

func IDerStringListCompare added in v0.27.5

func IDerStringListCompare[T IDer](ids []T, values []string) bool

IDerStringListCompare is a utility function that will compare a list of IDers with a list of strings to see if their values are equal.

func NoSelectionItemList

func NoSelectionItemList() []interface{}

NoSelectionItemList returns a default item list to start a selection list that allows no selection

func SelectOneItemList

func SelectOneItemList() []interface{}

SelectOneItemList returns a default item list to start a selection list that asks the user to select an item

func SortIds

func SortIds(ids []string)

SortIds sorts a list of auto-generated ids in numerical and hierarchical order. This is normally just called by the framework.

Types

type CheckboxList

type CheckboxList struct {
	MultiselectList
	// contains filtered or unexported fields
}

CheckboxList is a multi-select control that presents its choices as a list of checkboxes. Styling is provided by divs and spans that you can provide css for in your style sheets. The goradd.css file has default styling to handle the basics. It wraps the whole thing in a div that can be set to scroll as well, so that the final structure can be styled like a multi-column table, or a single-column scrolling list much like a standard html select list.

func GetCheckboxList

func GetCheckboxList(c page.ControlI, id string) *CheckboxList

GetCheckboxList is a convenience method to return the control with the given id from the page.

func NewCheckboxList

func NewCheckboxList(parent page.ControlI, id string) *CheckboxList

NewCheckboxList creates a new CheckboxList

func (*CheckboxList) ColumnCount

func (l *CheckboxList) ColumnCount() int

ColumnCount returns the current column count.

func (*CheckboxList) Deserialize

func (l *CheckboxList) Deserialize(dec page.Decoder)

func (*CheckboxList) DrawInnerHtml

func (l *CheckboxList) DrawInnerHtml(_ context.Context, w io.Writer)

DrawInnerHtml is called by the framework to draw the contents of the list.

func (*CheckboxList) DrawingAttributes

func (l *CheckboxList) DrawingAttributes(ctx context.Context) html5tag.Attributes

DrawingAttributes retrieves the tag's attributes at draw time. You should not normally need to call this, and the attributes are disposed of after drawing, so they are essentially read-only.

func (*CheckboxList) Init

func (l *CheckboxList) Init(self any, parent page.ControlI, id string)

Init is called by subclasses

func (*CheckboxList) LayoutDirection

func (l *CheckboxList) LayoutDirection() control.LayoutDirection

LayoutDirection returns the direction of how items are spread across the columns.

func (*CheckboxList) RenderItem

func (l *CheckboxList) RenderItem(item *Item) (h string)

RenderItem is called by the framework to render a single item in the list.

func (*CheckboxList) RenderItems

func (l *CheckboxList) RenderItems(items []*Item) string

func (*CheckboxList) Serialize

func (l *CheckboxList) Serialize(e page.Encoder)

func (*CheckboxList) SetColumnCount

func (l *CheckboxList) SetColumnCount(columns int) CheckboxListI

SetColumnCount sets the number of columns to use to display the list. Items will be evenly distributed across the columns.

func (*CheckboxList) SetIsScrolling

func (l *CheckboxList) SetIsScrolling(s bool) CheckboxListI

SetIsScrolling sets whether the list will scroll if it gets bigger than its bounding box. You will need to style the bounding box to give it limits, or else it will simply grow as big as the list.

func (*CheckboxList) SetLabelDrawingMode

func (l *CheckboxList) SetLabelDrawingMode(mode html5tag.LabelDrawingMode) CheckboxListI

SetLabelDrawingMode indicates how labels for each of the checkboxes are drawn.

func (*CheckboxList) SetLayoutDirection

func (l *CheckboxList) SetLayoutDirection(direction control.LayoutDirection) CheckboxListI

SetLayoutDirection specifies how items are distributed across the columns.

func (*CheckboxList) SetRowClass

func (l *CheckboxList) SetRowClass(c string) CheckboxListI

SetRowClass sets the class to the div wrapper around each row. If blank, will be given a default.

func (*CheckboxList) UpdateFormValues

func (l *CheckboxList) UpdateFormValues(ctx context.Context)

UpdateFormValues is used by the framework to cause the control to retrieve its values from the form

type CheckboxListCreator

type CheckboxListCreator struct {
	ID string
	// Items is a static list of labels and values that will be in the list. Or, use a DataProvider to dynamically generate the items.
	Items []ListValue
	// DataProvider is the control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProvider control.DataBinder
	// DataProviderID is the id of a control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProviderID string
	// ColumnCount specifies how many columns to show
	ColumnCount int
	// LayoutDirection determines how the items are arranged in the columns
	LayoutDirection control.LayoutDirection
	// LabelDrawingMode specifies how the labels on the radio buttons will be associated with the buttons
	LabelDrawingMode html5tag.LabelDrawingMode
	// IsScrolling will give the inner div a vertical scroll style. You will need to style the height of the outer control to have a fixed style as well.
	IsScrolling bool
	// RowClass is the class assigned to each row
	RowClass string
	// Value is the initial value of the textbox. Often its best to load the value in a separate Load step after creating the control.
	Value string
	// SaveState saves the selected value so that it is restored if the form is returned to.
	SaveState bool
	page.ControlOptions
}

func (CheckboxListCreator) Create

Create is called by the framework to create a new control from the Creator. You do not normally need to call this.

func (CheckboxListCreator) Init

type CheckboxListI

type CheckboxListI interface {
	MultiselectListI
	SetColumnCount(int) CheckboxListI
	SetLayoutDirection(direction control.LayoutDirection) CheckboxListI
	SetLabelDrawingMode(mode html5tag.LabelDrawingMode) CheckboxListI
	SetIsScrolling(s bool) CheckboxListI
	SetRowClass(c string) CheckboxListI

	RenderItems(items []*Item) string
	RenderItem(item *Item) string
}

type IDSetter

type IDSetter interface {
	SetID(id string)
}

IDSetter is an interface for an item that sets an ID.

type IDer

type IDer interface {
	ID() string
}

IDer is an object that has an ID.

type IdSlice

type IdSlice []string

IdSlice is a slice of string ids, and is used to sort a list of ids that the item list uses.

func (IdSlice) Len

func (p IdSlice) Len() int

func (IdSlice) Less

func (p IdSlice) Less(i, j int) bool

func (IdSlice) Swap

func (p IdSlice) Swap(i, j int)

type Item

type Item struct {
	List
	// contains filtered or unexported fields
}

An Item is an object that is a member of a list. HTML has a few different kinds of lists, and this can be a member of a select list (<select>), or an ordered or unordered list (<ul> or <ol>). It is up to the manager of the list to render the item, but this serves as a place to store options about the item. Not all options are pertinent to all lists.

A list item generally has a value, and a label. Often, lists will have ids too, that will appear in the html output, but the id values are managed by the list manager and generally should not be set by you. In situations where the user selects a list item, you would use the id to retrieve the Item selected.

func NewItem

func NewItem(label string, value ...string) *Item

NewItem creates a new item for a list. Specify an empty string for an item that represents no selection.

func NewItemFromItemIDer

func NewItemFromItemIDer(i ItemIDer) *Item

NewItemFromItemIDer creates a new item from any object that has an ID and String method. Note that the ID() of the ItemIDer will become the value of the select item, and the String() will become the label

func NewItemFromItemIntIDer

func NewItemFromItemIntIDer(i ItemIntIDer) *Item

func NewItemFromLabeler

func NewItemFromLabeler(l Labeler) *Item

NewItemFromLabeler creates a new item from any object that has just a Label method.

func NewItemFromStringer

func NewItemFromStringer(s fmt.Stringer) *Item

NewItemFromStringer creates a new item from any object that has just a String method. The label and value will be the same.

func NewItemFromValueLabeler

func NewItemFromValueLabeler(v ValueLabeler) *Item

NewItemFromValueLabeler creates a new item from any object that has a Value and Label method.

func (*Item) AddClass

func (i *Item) AddClass(class string) *Item

func (*Item) Anchor

func (i *Item) Anchor() string

func (*Item) AnchorAttributes

func (i *Item) AnchorAttributes() html5tag.Attributes

AnchorAttributes returns the attributes that will be used for each of the anchor tags.

You can directly set attributes on the returned value.

func (*Item) Attributes

func (i *Item) Attributes() html5tag.Attributes

Attributes returns a pointer to the attributes of the item for customization. You can directly set the attributes on the returned object.

func (*Item) Deserialize

func (i *Item) Deserialize(dec page.Decoder)

func (*Item) Disabled

func (i *Item) Disabled() bool

func (*Item) HasAnchor

func (i *Item) HasAnchor() bool

func (*Item) HasChildItems

func (i *Item) HasChildItems() bool

func (*Item) ID

func (i *Item) ID() string

func (*Item) IntValue

func (i *Item) IntValue() int

func (*Item) IsDivider

func (i *Item) IsDivider() bool

func (*Item) IsEmptyValue

func (i *Item) IsEmptyValue() bool

IsEmptyValue returns true if the value is empty, meaning it does not satisfy a selection being made if the list has IsRequired turned on.

func (*Item) Label

func (i *Item) Label() string

func (*Item) RenderLabel

func (i *Item) RenderLabel() (h string)

RenderLabel is called by list implementations to render the item.

func (*Item) Serialize

func (i *Item) Serialize(e page.Encoder)

func (*Item) SetAnchor

func (i *Item) SetAnchor(a string) *Item

SetAnchor assigns the value of the href attribute. This will cause the item to output with an anchor tag (a).

func (*Item) SetAttribute

func (i *Item) SetAttribute(key, value string) *Item

func (*Item) SetDisabled

func (i *Item) SetDisabled(d bool)

func (*Item) SetID

func (i *Item) SetID(id string)

SetID should not be called by your code typically. It is exported for implementations of item lists. The IDs of an item list are completely managed by the list, you cannot have custom ids.

func (*Item) SetIsDivider

func (i *Item) SetIsDivider(d bool)

func (*Item) SetLabel

func (i *Item) SetLabel(l string)

func (*Item) SetShouldEscapeLabel

func (i *Item) SetShouldEscapeLabel(e bool) *Item

func (*Item) SetValue

func (i *Item) SetValue(v string) *Item

func (*Item) Value

func (i *Item) Value() string

type ItemIDer

type ItemIDer interface {
	ID() string
	String() string
}

ItemIDer is an interface to a listable object that matches most orm objects

type ItemIntIDer

type ItemIntIDer interface {
	ID() int
	String() string
}

ItemIntIDer matches orm objects that use an int type for the id

type Labeler

type Labeler interface {
	Label() string
}

type List

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

List manages a list of *Item items. List is designed to be embedded in another structure, and will turn that object into a manager of list items. List will manage the id's of the items in its list, you do not have control of that, and it needs to manage those ids in order to efficiently manage the selection process.

Controls that embed this must implement the Serialize and Deserialize methods to call both the ControlBase's Serialize and Deserialize methods, and the ones here.

func NewList

func NewList(owner IDer) List

NewList creates a new item list. "owner" is the object that has the list embedded in it, and must be an IDer.

func (*List) Add

func (l *List) Add(label string, value ...string) *Item

Add adds the given item to the end of the list. The value is optional, but should only be one or zero values.

func (*List) AddAt

func (l *List) AddAt(index int, label string, value ...string)

AddAt adds the item at the given index. If the index is negative, it counts from the end. -1 would therefore put the item before the last item. If the index is bigger or equal to the number of items, it adds it to the end. If the index is zero, or is negative and smaller than the negative value of the number of items, it adds to the beginning. This can be an expensive operation in a long hierarchical list, so use sparingly.

func (*List) AddItemAt

func (l *List) AddItemAt(index int, item *Item)

AddItemAt adds the item at the given index. If the index is negative, it counts from the end. If the index is -1 or bigger than the number of items, it adds it to the end. If the index is zero, or is negative and smaller than the negative value of the number of items, it adds to the beginning. This can be an expensive operation in a long hierarchical list, so use sparingly.

func (*List) AddItems

func (l *List) AddItems(items ...interface{})

AddItems adds one or more objects to the end of the list. items should be a list of *Item, ValueLabeler, ItemIDer, Labeler or Stringer types. This function can accept one or more lists of items, or single items

func (*List) Clear

func (l *List) Clear()

Clear removes all the items from the list.

func (*List) Deserialize

func (l *List) Deserialize(dec page.Decoder)

func (*List) GetItemByID

func (l *List) GetItemByID(id string) (foundItem *Item)

GetItemByID recursively searches for and returns the item corresponding to the given id. Since we are managing the id numbers, we can efficiently find the item. Note that if you add items to the list, the ids may change.

func (*List) GetItemByValue

func (l *List) GetItemByValue(value string) (id string, foundItem *Item)

GetItemByValue recursively searches the list to find the item with the given value. It starts with the current list, and if not found, will search in sublists.

func (*List) ItemAt

func (l *List) ItemAt(index int) *Item

ItemAt retrieves an item by index.

func (*List) Items

func (l *List) Items() []*Item

Items returns a slice of the *Item items, in the order they were added or arranged.

func (*List) Len

func (l *List) Len() int

Len returns the length of the item list at the current level. In other words, it does not count items in sublists.

func (*List) RemoveAt

func (l *List) RemoveAt(index int)

RemoveAt removes an item at the given index.

func (*List) Serialize

func (l *List) Serialize(e page.Encoder)

type ListI

type ListI interface {
	Add(label string, value ...string) *Item
	AddAt(index int, label string, value ...string)
	AddItemAt(index int, item *Item)
	AddItems(items ...interface{})
	ItemAt(index int) *Item
	Items() []*Item
	Clear()
	RemoveAt(index int)
	Len() int
	GetItemByID(id string) (foundItem *Item)
	GetItemByValue(value string) (id string, foundItem *Item)
	// contains filtered or unexported methods
}

ListI is the interface for all controls that display a list of Items.

type ListValue

type ListValue struct {
	L string
	// V is the value
	V interface{}
}

ListValue is a helper for initializing a control based on List. It satisfies the ValueLabeler interface. To use it, create a slice of ListValue's and pass the list to AddItems or SetData.

func (ListValue) Label

func (l ListValue) Label() string

func (ListValue) Value

func (l ListValue) Value() interface{}

type MultiselectList

type MultiselectList struct {
	page.ControlBase
	List
	control2.DataManager
	// contains filtered or unexported fields
}

MultiselectList is a generic list box which allows multiple selections. It is here for completeness, but is not used very often since it doesn't present an intuitive interface and is very browser dependent on what is presented. A CheckboxList is better.

func GetMultiselectList

func GetMultiselectList(c page.ControlI, id string) *MultiselectList

GetMultiselectList is a convenience method to return the control with the given id from the page.

func NewMultiselectList

func NewMultiselectList(parent page.ControlI, id string) *MultiselectList

func (*MultiselectList) Deserialize

func (l *MultiselectList) Deserialize(dec page.Decoder)

func (*MultiselectList) DrawInnerHtml

func (l *MultiselectList) DrawInnerHtml(_ context.Context, w io.Writer)

func (*MultiselectList) DrawTag

func (l *MultiselectList) DrawTag(ctx context.Context, w io.Writer)

func (*MultiselectList) DrawingAttributes

func (l *MultiselectList) DrawingAttributes(ctx context.Context) html5tag.Attributes

DrawingAttributes retrieves the tag's attributes at draw time. You should not normally need to call this, and the attributes are disposed of after drawing, so they are essentially read-only.

func (*MultiselectList) Init

func (l *MultiselectList) Init(self any, parent page.ControlI, id string)

func (*MultiselectList) IsValueSelected

func (l *MultiselectList) IsValueSelected(v string) bool

func (*MultiselectList) MarshalState

func (l *MultiselectList) MarshalState(m page.SavedState)

MarshalState is an internal function to save the state of the control

func (*MultiselectList) SelectedIds

func (l *MultiselectList) SelectedIds() []string

SelectedIds returns a list of ids sorted by id number that correspond to the selection

func (*MultiselectList) SelectedItems

func (l *MultiselectList) SelectedItems() []*Item

func (*MultiselectList) SelectedLabels

func (l *MultiselectList) SelectedLabels() []string

func (*MultiselectList) SelectedValues

func (l *MultiselectList) SelectedValues() []string

func (*MultiselectList) Serialize

func (l *MultiselectList) Serialize(e page.Encoder)

func (*MultiselectList) SetData

func (l *MultiselectList) SetData(data interface{})

SetData overrides the default data setter to add objects to the item list. The result is kept in memory currently. ValueLabeler, ItemIDer, Labeler or Stringer types. This function can accept one or more lists of items, or single items.

func (*MultiselectList) SetSelectedValueNoRefresh

func (l *MultiselectList) SetSelectedValueNoRefresh(value string, on bool)

func (*MultiselectList) SetSelectedValues

func (l *MultiselectList) SetSelectedValues(values []string)

SetSelectedValues sets the current selection to the given values. You must ensure that the items with the values exist, it will not attempt to make sure the items exist.

func (*MultiselectList) SetSelectedValuesNoRefresh

func (l *MultiselectList) SetSelectedValuesNoRefresh(values []string)

func (*MultiselectList) SetSize

func (l *MultiselectList) SetSize(size int) MultiselectListI

func (*MultiselectList) SetValue

func (l *MultiselectList) SetValue(v interface{})

SetValue implements the Valuer interface for general purpose value getting and setting

func (*MultiselectList) Size

func (l *MultiselectList) Size() int

func (*MultiselectList) UnmarshalState

func (l *MultiselectList) UnmarshalState(m page.SavedState)

UnmarshalState is an internal function to restore the state of the control

func (*MultiselectList) UpdateFormValues

func (l *MultiselectList) UpdateFormValues(ctx context.Context)

UpdateFormValues is used by the framework to cause the control to retrieve its values from the form

func (*MultiselectList) Validate

func (l *MultiselectList) Validate(_ context.Context) bool

func (*MultiselectList) Value

func (l *MultiselectList) Value() interface{}

Value implements the Valuer interface for general purpose value getting and setting.

func (*MultiselectList) ValueString added in v0.26.0

func (l *MultiselectList) ValueString() string

ValueString returns the values as a comma-delimited string.

type MultiselectListCreator

type MultiselectListCreator struct {
	ID string
	// Items is a static list of labels and values that will be in the list. Or, use a DataProvider to dynamically generate the items.
	Items []ListValue
	// DataProvider is the control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProvider control2.DataBinder
	// DataProviderID is the id of a control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProviderID string
	// Size specifies how many items to show, and turns the list into a scrolling list
	Size int
	// SaveState saves the selected value so that it is restored if the form is returned to.
	SaveState bool
	page.ControlOptions
}

func (MultiselectListCreator) Create

type MultiselectListI

type MultiselectListI interface {
	page.ControlI
	ListI
	control2.DataManagerI
}

type OrderedList

type OrderedList struct {
	UnorderedList
}

OrderedList is a dynamically generated html ordered list (ol). Such lists are often used as the basis for javascript and css widgets. If you use a data provider to set the data, you should call AddItems to the list in your LoadData function.

func GetOrderedList

func GetOrderedList(c page.ControlI, id string) *OrderedList

GetOrderedList is a convenience method to return the control with the given id from the page.

func NewOrderedList

func NewOrderedList(parent page.ControlI, id string) *OrderedList

NewOrderedList creates a new ordered list (ol tag).

func (*OrderedList) DrawInnerHtml

func (l *OrderedList) DrawInnerHtml(_ context.Context, w io.Writer)

func (*OrderedList) Init

func (l *OrderedList) Init(self any, parent page.ControlI, id string)

func (*OrderedList) NumberType

func (l *OrderedList) NumberType() string

NumberType returns the string used for the type attribute.

func (*OrderedList) SetNumberType

func (l *OrderedList) SetNumberType(t string) OrderedListI

SetNumberType sets the top level number style for the list. Choose from the OrderedListNumberType* constants. To set a number type for a sublevel, set the "type" attribute on the list item that is the parent of the sub list.

func (*OrderedList) SetStart

func (l *OrderedList) SetStart(start int) OrderedListI

SetStart sets the starting number for the numbers in the top level list. To set the start of a sub-list, set the "start" attribute on the list item that is the parent of the sub-list.

type OrderedListCreator

type OrderedListCreator struct {
	ID string
	// Items is a static list of labels and values that will be in the list. Or, use a DataProvider to dynamically generate the items.
	Items []ListValue
	// DataProvider is the control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProvider control.DataBinder
	// DataProviderID is the id of a control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProviderID string
	// NumberType is the type attribute and defaults to OrderedListNumberTypeNumber.
	NumberType string
	// StartAt sets the number to start counting from. The default is 1.
	StartAt int
	page.ControlOptions
}

func (OrderedListCreator) Create

Create is called by the framework to create a new control from the Creator. You do not normally need to call this.

func (OrderedListCreator) Init

func (c OrderedListCreator) Init(ctx context.Context, ctrl OrderedListI)

type OrderedListI

type OrderedListI interface {
	UnorderedListI
	SetNumberType(t string) OrderedListI
	SetStart(start int) OrderedListI
}

type RadioList

type RadioList struct {
	SelectList
	// contains filtered or unexported fields
}

RadioList is a single-select control that presents its choices as a list of radio buttons. Styling is provided by divs and spans that you can provide css for in your style sheets. The goradd.css file has default styling to handle the basics. It wraps the whole thing in a div that can be set to scroll as well, so that the final structure can be styled like a multi-column table, or a single-table scrolling list much like a standard html select list.

func GetRadioList

func GetRadioList(c page.ControlI, id string) *RadioList

GetRadioList is a convenience method to return the control with the given id from the page.

func NewRadioList

func NewRadioList(parent page.ControlI, id string) *RadioList

NewRadioList creates a new RadioList control.

func (*RadioList) ColumnCount

func (l *RadioList) ColumnCount() int

ColumnCount returns the current column count.

func (*RadioList) Deserialize

func (l *RadioList) Deserialize(dec page.Decoder)

func (*RadioList) DrawInnerHtml

func (l *RadioList) DrawInnerHtml(_ context.Context, w io.Writer)

DrawInnerHtml is called by the framework to draw the contents of the list.

func (*RadioList) DrawingAttributes

func (l *RadioList) DrawingAttributes(ctx context.Context) html5tag.Attributes

DrawingAttributes retrieves the tag's attributes at draw time. You should not normally need to call this, and the attributes are disposed of after drawing, so they are essentially read-only.

func (*RadioList) Init

func (l *RadioList) Init(self any, parent page.ControlI, id string)

Init is called by subclasses.

func (*RadioList) LayoutDirection

func (l *RadioList) LayoutDirection() control.LayoutDirection

LayoutDirection returns the direction of how items are spread across the columns.

func (*RadioList) RenderItem

func (l *RadioList) RenderItem(item *Item) (h string)

RenderItem is called by the framework to render a single item in the list.

func (*RadioList) RenderItems

func (l *RadioList) RenderItems(items []*Item) string

func (*RadioList) Serialize

func (l *RadioList) Serialize(e page.Encoder)

func (*RadioList) SetColumnCount

func (l *RadioList) SetColumnCount(columns int) RadioListI

SetColumnCount sets the number of columns to use to display the list. Items will be evenly distributed across the columns.

func (*RadioList) SetIsScrolling

func (l *RadioList) SetIsScrolling(s bool) RadioListI

SetIsScrolling sets whether the list will scroll if it gets bigger than its bounding box. You will need to style the bounding box to give it limits, or else it will simply grow as big as the list.

func (*RadioList) SetLabelDrawingMode

func (l *RadioList) SetLabelDrawingMode(mode html5tag.LabelDrawingMode) RadioListI

SetLabelDrawingMode indicates how labels for each of the checkboxes are drawn.

func (*RadioList) SetLayoutDirection

func (l *RadioList) SetLayoutDirection(direction control.LayoutDirection) RadioListI

SetLayoutDirection specifies how items are distributed across the columns.

func (*RadioList) SetRowClass

func (l *RadioList) SetRowClass(c string) RadioListI

SetRowClass sets the class to the div wrapper around each row. If blank, will be given a default.

func (*RadioList) UpdateFormValues

func (l *RadioList) UpdateFormValues(ctx context.Context)

UpdateFormValues is used by the framework to cause the control to retrieve its values from the form

type RadioListCreator

type RadioListCreator struct {
	ID string
	// Items is a static list of labels and values that will be in the list. Or, use a DataProvider to dynamically generate the items.
	Items []ListValue
	// DataProvider is the control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProvider control.DataBinder
	// DataProviderID is the id of a control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProviderID string
	// ColumnCount specifies how many columns to show
	ColumnCount int
	// LayoutDirection determines how the items are arranged in the columns
	LayoutDirection control.LayoutDirection
	// LabelDrawingMode specifies how the labels on the radio buttons will be associated with the buttons
	LabelDrawingMode html5tag.LabelDrawingMode
	// IsScrolling will give the inner div a vertical scroll style. You will need to style the height of the outer control to have a fixed style as well.
	IsScrolling bool
	// RowClass is the class assigned to each row
	RowClass string
	// Value is the initial value of the textbox. Often its best to load the value in a separate Load step after creating the control.
	Value string
	// OnChange is the action to take when any of the radio buttons in the list change
	OnChange action.ActionI
	// SaveState saves the selected value so that it is restored if the form is returned to.
	SaveState bool

	page.ControlOptions
}

func (RadioListCreator) Create

func (c RadioListCreator) Create(ctx context.Context, parent page.ControlI) page.ControlI

Create is called by the framework to create a new control from the Creator. You do not normally need to call this.

func (RadioListCreator) Init

func (c RadioListCreator) Init(ctx context.Context, ctrl RadioListI)

type RadioListI

type RadioListI interface {
	SelectListI
	SetColumnCount(int) RadioListI
	SetLayoutDirection(direction control.LayoutDirection) RadioListI
	SetLabelDrawingMode(mode html5tag.LabelDrawingMode) RadioListI
	SetIsScrolling(s bool) RadioListI
	SetRowClass(c string) RadioListI

	RenderItems(items []*Item) string
	RenderItem(item *Item) string
}

type SelectList

type SelectList struct {
	page.ControlBase
	List
	control2.DataManager
	// contains filtered or unexported fields
}

SelectList is typically a dropdown list with a single selection. Items are selected by id number, and the SelectList completely controls the ids in the list. Create the list by calling Add or AddItems to add *Item objects. Or, use the embedded DataManager to load items. Set the size attribute if you want to display it as a scrolling list rather than a dropdown list.

func GetSelectList

func GetSelectList(c page.ControlI, id string) *SelectList

GetSelectList is a convenience method to return the control with the given id from the page.

func NewSelectList

func NewSelectList(parent page.ControlI, id string) *SelectList

NewSelectList creates a new select list

func (*SelectList) Deserialize

func (l *SelectList) Deserialize(dec page.Decoder)

func (*SelectList) DrawInnerHtml

func (l *SelectList) DrawInnerHtml(_ context.Context, w io.Writer)

DrawInnerHtml is called by the framework during drawing of the control to draw the inner html of the control

func (*SelectList) DrawTag

func (l *SelectList) DrawTag(ctx context.Context, w io.Writer)

func (*SelectList) DrawingAttributes

func (l *SelectList) DrawingAttributes(ctx context.Context) html5tag.Attributes

DrawingAttributes retrieves the tag's attributes at draw time. You should not normally need to call this, and the attributes are disposed of after drawing, so they are essentially read-only.

func (*SelectList) Init

func (l *SelectList) Init(self any, parent page.ControlI, id string)

Init is called by subclasses.

func (*SelectList) IntValue

func (l *SelectList) IntValue() int

IntValue returns the select value as an integer.

func (*SelectList) MarshalState

func (l *SelectList) MarshalState(m page.SavedState)

MarshalState is an internal function to save the state of the control

func (*SelectList) SelectedItem

func (l *SelectList) SelectedItem() *Item

SelectedItem will return the currently selected item. If no item has been selected, it will return the first item in the list, since that is what will be showing in the selection list, and will update its internal pointer to make the first item the current selection.

func (*SelectList) SelectedLabel

func (l *SelectList) SelectedLabel() string

SelectedLabel returns the label of the selected item

func (*SelectList) Serialize

func (l *SelectList) Serialize(e page.Encoder)

func (*SelectList) SetData

func (l *SelectList) SetData(data interface{})

SetData overrides the default data setter to add objects to the item list. The result is kept in memory currently. ValueLabeler, ItemIDer, Labeler or Stringer types. This function can accept one or more lists of items, or single items.

func (*SelectList) SetSelectedValue

func (l *SelectList) SetSelectedValue(v string)

SetSelectedValue sets the current selection to the given id.

If you are using a DataProvider, you must make sure that the value will exist in the list. Otherwise it will compare against the current item list and panic if the item does not exist.

func (*SelectList) SetValue

func (l *SelectList) SetValue(v interface{})

SetValue implements the Valuer interface for general purpose value getting and setting

func (*SelectList) StringValue

func (l *SelectList) StringValue() string

StringValue returns the selected value as a string

func (*SelectList) UnmarshalState

func (l *SelectList) UnmarshalState(m page.SavedState)

UnmarshalState is an internal function to restore the state of the control

func (*SelectList) UpdateFormValues

func (l *SelectList) UpdateFormValues(ctx context.Context)

UpdateFormValues is used by the framework to cause the control to retrieve its values from the form

func (*SelectList) Validate

func (l *SelectList) Validate(ctx context.Context) bool

Validate is called by the framework to validate the contents of the control. For a SelectList, this is typically just checking to see if something was selected if a selection is required.

func (*SelectList) Value

func (l *SelectList) Value() interface{}

Value implements the Valuer interface for general purpose value getting and setting

type SelectListCreator

type SelectListCreator struct {
	ID string
	// Items is a static list of labels and values that will be in the list. Or, use a DataProvider to dynamically generate the items.
	Items []ListValue
	// NilItem is a helper to add an item at the top of the list with a nil value. This is often
	// used to specify no selection, or a message that a selection is required. This only works
	// if you are NOT using a DataProvider
	NilItem string
	// DataProvider is the control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProvider control2.DataBinder
	// DataProviderID is the id of a control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProviderID string
	// Size specifies how many items to show, and turns the list into a scrolling list
	Size int
	// Value is the initial value of the list. Often its best to load the value in a separate Load step after creating the control.
	Value string
	// OnChange is an action to take when the user changes what is selected (as in, when the javascript change event fires).
	OnChange action.ActionI
	// SaveState saves the selected value so that it is restored if the form is returned to.
	SaveState bool
	page.ControlOptions
}

func (SelectListCreator) Create

func (c SelectListCreator) Create(ctx context.Context, parent page.ControlI) page.ControlI

func (SelectListCreator) Init

func (c SelectListCreator) Init(ctx context.Context, ctrl SelectListI)

type SelectListI

type SelectListI interface {
	page.ControlI
	ListI
	control2.DataManagerI
	SetValue(v interface{})
	Value() interface{}
	IntValue() int
}

func GetSelectListI

func GetSelectListI(c page.ControlI, id string) SelectListI

type UnorderedList

type UnorderedList struct {
	page.ControlBase
	List
	control2.DataManager
	// contains filtered or unexported fields
}

UnorderedList is a dynamically generated html unordered list (ul). Such lists are often used as the basis for javascript and css widgets. If you use a data provider to set the data, you should call AddItems to the list in your LoadData function.

func GetUnorderedList

func GetUnorderedList(c page.ControlI, id string) *UnorderedList

GetUnorderedList is a convenience method to return the control with the given id from the page.

func NewUnorderedList

func NewUnorderedList(parent page.ControlI, id string) *UnorderedList

NewUnorderedList creates a new ul type list.

func (*UnorderedList) Deserialize

func (l *UnorderedList) Deserialize(dec page.Decoder)

func (*UnorderedList) DrawInnerHtml

func (l *UnorderedList) DrawInnerHtml(_ context.Context, w io.Writer)

DrawInnerHtml is called by the framework to draw the content of the tag.

func (*UnorderedList) DrawTag

func (l *UnorderedList) DrawTag(ctx context.Context, w io.Writer)

func (*UnorderedList) DrawingAttributes

func (l *UnorderedList) DrawingAttributes(ctx context.Context) html5tag.Attributes

DrawingAttributes retrieves the tag's attributes at draw time. You should not normally need to call this, and the attributes are disposed of after drawing, so they are essentially read-only.

func (*UnorderedList) GetItemsHtml

func (l *UnorderedList) GetItemsHtml(items []*Item) string

GetItemsHtml returns the HTML for the items. It is exported so that it can be overridden by other implementations of an UnorderedList.

func (*UnorderedList) Init

func (l *UnorderedList) Init(self any, parent page.ControlI, id string)

func (*UnorderedList) ItemTag

func (l *UnorderedList) ItemTag() string

ItemTag returns the HTML tag for an item in the list.

func (*UnorderedList) Serialize

func (l *UnorderedList) Serialize(e page.Encoder)

func (*UnorderedList) SetBulletStyle

func (l *UnorderedList) SetBulletStyle(s string) UnorderedListI

SetBulletStyle sets the list-style-type attribute of the list. Choose from the UnorderedListStyle* constants.

func (*UnorderedList) SetData

func (l *UnorderedList) SetData(data interface{})

SetData replaces the current list with the given data. ValueLabeler, ItemIDer, Labeler or Stringer types are accepted. This function can accept one or more lists of items, or single items. They will all get added to the top level of the list. To add sub items, get a list item and add items to it.

func (*UnorderedList) SetItemTag

func (l *UnorderedList) SetItemTag(s string) UnorderedListI

SetItemTag sets the tag that will be used for items in the list. By default this is "li".

type UnorderedListCreator

type UnorderedListCreator struct {
	ID string
	// Items is a static list of labels and values that will be in the list. Or, use a DataProvider to dynamically generate the items.
	Items []ListValue
	// DataProvider is the control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProvider control2.DataBinder
	// DataProviderID is the id of a control that will dynamically provide the data for the list and that implements the DataBinder interface.
	DataProviderID string
	// BulletStyle is the list-style-type property.
	BulletStyle string
	page.ControlOptions
}

UnorderedListCreator is a declarative helper to create an UnorderedListControl. Pass it to control.AddControls() to add the declared list to the control.

func (UnorderedListCreator) Create

Create is called by the framework to create a new control from the Creator. You do not normally need to call this.

func (UnorderedListCreator) Init

type UnorderedListI

type UnorderedListI interface {
	page.ControlI
	ListI
	control2.DataManagerI
	GetItemsHtml(items []*Item) string
	SetBulletStyle(s string) UnorderedListI
	SetItemTag(s string) UnorderedListI
	ItemTag() string
}

type ValueLabeler

type ValueLabeler interface {
	Value() interface{}
	Label() string
}

Jump to

Keyboard shortcuts

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