Documentation ¶
Index ¶
- Constants
- func Editor(schema schema.Schema, element Element, value any, ...) (string, error)
- func LookupCodeSchema() schema.Element
- func SortLookupCodeByGroupThenLabel(a LookupCode, b LookupCode) bool
- func SortLookupCodeByLabel(a LookupCode, b LookupCode) bool
- func Use(name string, widget Widget)
- func Viewer(schema schema.Schema, element Element, value any, ...) (string, error)
- type Element
- func (element *Element) AllElements() []*Element
- func (element *Element) Edit(schema *schema.Schema, lookupProvider LookupProvider, value any, ...) error
- func (element *Element) Encoding() string
- func (element *Element) GetSchema(s *schema.Schema) schema.Element
- func (element *Element) GetSliceOfString(value any, s *schema.Schema) []string
- func (element *Element) GetString(value any, s *schema.Schema) string
- func (element Element) IsEmpty() bool
- func (element *Element) UnmarshalMap(data map[string]any) error
- func (element *Element) View(schema *schema.Schema, lookupProvider LookupProvider, value any, ...) error
- func (element *Element) Widget() (Widget, error)
- type Form
- func (form *Form) BuildEditor(value any, lookupProvider LookupProvider, builder *html.Builder) error
- func (form *Form) BuildViewer(value any, lookupProvider LookupProvider, builder *html.Builder) error
- func (form *Form) Editor(value any, lookupProvider LookupProvider) (string, error)
- func (form *Form) Encoding() string
- func (form *Form) SetAll(object any, value mapof.Any, lookupProvider LookupProvider) error
- func (form *Form) SetURLValues(object any, value url.Values, lookupProvider LookupProvider) error
- func (form *Form) Viewer(value any, lookupProvider LookupProvider) (string, error)
- type LookupCode
- type LookupCodeMaker
- type LookupGroup
- type LookupProvider
- type ReadOnlyLookupGroup
- type Rule
- type UnmarshalMaper
- type Widget
- type WritableLookupGroup
Constants ¶
const NewItemIdentifier = "::NEWVALUE::"
NewItemItentifier is a prefix appended to select options when the User wants to add a new item into a WritableLookupGroup
Variables ¶
This section is empty.
Functions ¶
func Editor ¶ added in v0.10.0
func Editor(schema schema.Schema, element Element, value any, lookupProvider LookupProvider) (string, error)
Viewer creates an in-place form and executes its "Editorr" method
func LookupCodeSchema ¶ added in v0.22.9
func SortLookupCodeByGroupThenLabel ¶ added in v0.15.0
func SortLookupCodeByGroupThenLabel(a LookupCode, b LookupCode) bool
SortLookupCodeByGroupThenLabel is a sort function that works with the sort.Slice function.
func SortLookupCodeByLabel ¶ added in v0.15.0
func SortLookupCodeByLabel(a LookupCode, b LookupCode) bool
SortLookupCodeByLabel is a sort function that works with the sort.Slice function.
Types ¶
type Element ¶ added in v0.9.1
type Element struct { Type string `json:"type"` // The kind of form element ID string `json:"id"` // The ID of the element (needed by some widgets) Path string `json:"path"` // Path to the data value displayed in for this form element Label string `json:"label,omitempty"` // Short label to be displayed on the form element Description string `json:"description,omitempty"` // Longer description text to be displayed on the form element Options mapof.Any `json:"options,omitempty"` // Additional custom properties defined by individual widgets Children []Element `json:"children,omitempty"` // Array of sub-form elements that may be displayed depending on the kind. ReadOnly bool `json:"readOnly,omitempty"` // If true, then this element is read-only }
Element defines a single form element, or a nested form layout. It can be serialized to and from a database.
func MustParse ¶ added in v0.4.0
MustParse guarantees that a value has been parsed into a Form, or else it panics the application.
func NewElement ¶ added in v0.9.1
func NewElement() Element
func Parse ¶ added in v0.3.9
Parse attempts to convert a value into a Form. Currently supports map[string]any, []byte, string, and UnmarshalMaper interface.
func (*Element) AllElements ¶ added in v0.9.1
AllPaths returns pointers to all of the valid paths in this form
func (*Element) GetSchema ¶ added in v0.20.0
GetSchema finds and returns the schema.Element associated with this Element path
func (*Element) GetSliceOfString ¶ added in v0.9.1
GetSliceOfString rturns a slice of strings for a provided path.
func (*Element) GetString ¶ added in v0.9.1
GetValue returns the value of the element at the provided path. If the schema is present, then it is used to resolve the value. If the schema is not present, then the value is returned using path lookup instead.
func (*Element) UnmarshalMap ¶ added in v0.9.1
UnmarshalMap parses data from a generic structure (mapof.Any) into a Form record.
type Form ¶
func (*Form) BuildEditor ¶ added in v0.10.0
func (form *Form) BuildEditor(value any, lookupProvider LookupProvider, builder *html.Builder) error
BuildEditor generates an editable view of this form
func (*Form) BuildViewer ¶ added in v0.10.0
func (form *Form) BuildViewer(value any, lookupProvider LookupProvider, builder *html.Builder) error
BuildViewer generates a read-only view of this form
func (*Form) Editor ¶ added in v0.10.0
func (form *Form) Editor(value any, lookupProvider LookupProvider) (string, error)
DrawString() generates this form as a string
func (*Form) Encoding ¶ added in v0.20.0
Encoding returns the "enctype" attribute for the form. Default is ""
func (*Form) SetAll ¶ added in v0.13.1
Do applies all of the data from the value map into the target object
func (*Form) SetURLValues ¶ added in v0.22.12
Do applies all of the data from the value map into the target object
type LookupCode ¶ added in v0.9.1
type LookupCode struct { Value string `json:"value,omitempty" form:"value" bson:"value,omitempty"` // Internal value of the LookupCode Label string `json:"label,omitempty" form:"label" bson:"label,omitempty"` // Human-friendly label/name of the LookupCode Description string `json:"description,omitempty" form:"description" bson:"description,omitempty"` // Optional long description of the LookupCode Icon string `json:"icon,omitempty" form:"icon" bson:"icon,omitempty"` // Optional icon to use when displaying the LookupCode Group string `json:"group,omitempty" form:"group" bson:"group,omitempty"` // Optiional grouping to use when displaying the LookupCode Href string `json:"href,omitempty" form:"href" bson:"href,omitempty"` // Optional URL to use when using this LookupCode }
LookupCode represents a single value/label pair to be used in place of Enums for optional lists.
func AsLookupCode ¶ added in v0.16.0
func AsLookupCode[T LookupCodeMaker](maker T) LookupCode
AsLookupCode is a helper function that converts any object that implements the LookupCodeMaker interface into a form.LookupCode
func GetLookupCodes ¶ added in v0.9.1
func GetLookupCodes(element *Element, schemaElement schema.Element, lookupProvider LookupProvider) ([]LookupCode, bool)
GetLookupCodes returns a list of LookupCodes derived from: 1) an "enum" (string or slice-of-lookupCode) in the form element, 2) a "datasource" value that is looked up in the lookupProvider 3) a value enumerated in the schema
The boolean value is TRUE if this comes from a WritableLookupGroup
func NewLookupCode ¶ added in v0.9.1
func NewLookupCode(value string) LookupCode
NewLookupCode creates a new LookupCode from a string
func ParseLookupCode ¶ added in v0.15.2
func ParseLookupCode(value any) LookupCode
func (*LookupCode) GetPointer ¶ added in v0.15.5
func (lookupCode *LookupCode) GetPointer(name string) (any, bool)
func (LookupCode) ID ¶ added in v0.12.0
func (lookupCode LookupCode) ID() string
ID returns the unique ID of the LookupCode, allowing them to be used as a set.Value
type LookupCodeMaker ¶ added in v0.16.0
type LookupCodeMaker interface { // LookupCode returns the data from current object in the form of a form.LookupCode LookupCode() LookupCode }
LookupCodeMaker is an interface that wraps the LookupCode method
type LookupGroup ¶ added in v0.13.1
type LookupGroup interface {
Get() []LookupCode
}
LookupGroup is an read-only interface that returns a list of LookupCodes
type LookupProvider ¶ added in v0.9.1
type LookupProvider interface {
Group(name string) LookupGroup
}
LookupProvider is an external object that can inject LookupCodes based on their URL.
type ReadOnlyLookupGroup ¶ added in v0.13.1
type ReadOnlyLookupGroup []LookupCode
ReadOnlyLookupGroup is a simple implementation of the LookupGroup interface that returns a static list of LookupCodes.
func NewReadOnlyLookupGroup ¶ added in v0.13.1
func NewReadOnlyLookupGroup(codes ...LookupCode) ReadOnlyLookupGroup
NewReadOnlyLookupGroup returns a fully initialized ReadOnlyLookupGroup
func (ReadOnlyLookupGroup) Get ¶ added in v0.13.1
func (group ReadOnlyLookupGroup) Get() []LookupCode
Get returns the list of LookupCodes
func (ReadOnlyLookupGroup) Value ¶ added in v0.22.8
func (group ReadOnlyLookupGroup) Value(value string) LookupCode
Value returns the LookupCode that matches the provided value, and an empty LookupCode if no match is found.
type Rule ¶ added in v0.6.0
func (Rule) HyperscriptRules ¶ added in v0.6.0
type UnmarshalMaper ¶ added in v0.6.4
type UnmarshalMaper interface { // UnmarshalMap returns a value in the format map[string]interface UnmarshalMap() map[string]any }
UnmarshalMaper wraps the UnmarshalMap interface
type Widget ¶ added in v0.10.0
type Widget interface { View(element *Element, schema *schema.Schema, lookupProvider LookupProvider, value any, builder *html.Builder) error Edit(element *Element, schema *schema.Schema, lookupProvider LookupProvider, value any, builder *html.Builder) error ShowLabels() bool Encoding(element *Element) string }
Widget defines a data type that can be included in a form
type WritableLookupGroup ¶ added in v0.13.1
type WritableLookupGroup interface { LookupGroup Add(name string) (string, error) }
WriteableLookupGroup is a read-write interface that returns a list of LookupCodes, and can add new codes to the list.