container

package
v0.9.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodesFromJSONSchema

func NodesFromJSONSchema(ctx context.Context, group node.Group, jsonSchemaRef, prefix string, compiler *jsonschema.Compiler) (node.Nodes, error)

Types

type CSRFSetter

type CSRFSetter interface {
	// SetCSRF sets the CSRF value.
	SetCSRF(string)
}

type Container

type Container struct {
	// Action should be used as the form action URL `<form action="{{ .Action }}" method="post">`.
	//
	// required: true
	Action string `json:"action" faker:"url"`

	// Method is the form method (e.g. POST)
	//
	// required: true
	Method string `json:"method" faker:"http_method"`

	// Nodes contains the form's nodes
	//
	// The form's nodes can be input fields, text, images, and other UI elements.
	//
	// required: true
	Nodes node.Nodes `json:"nodes"`

	// Messages contains all global form messages and errors.
	Messages text.Messages `json:"messages,omitempty"`
}

Container represents a HTML Form. The container can work with both HTTP Form and JSON requests

swagger:model uiContainer

func New

func New(action string) *Container

New returns an empty container.

func NewFromHTTPRequest

func NewFromHTTPRequest(r *http.Request, group node.Group, action string, compiler decoderx.HTTPDecoderOption) (*Container, error)

NewFromHTTPRequest creates a new Container and populates fields by parsing the HTTP Request body. A jsonSchemaRef needs to be added to allow HTTP Form Post Body parsing.

func NewFromJSON

func NewFromJSON(action string, group node.Group, raw json.RawMessage, prefix string) *Container

NewFromJSON creates a UI Container based on the provided JSON struct.

func NewFromJSONSchema

func NewFromJSONSchema(ctx context.Context, action string, group node.Group, jsonSchemaRef, prefix string, compiler *jsonschema.Compiler) (*Container, error)

NewFromJSONSchema creates a new Container and populates the fields using the provided JSON Schema.

func (*Container) AddMessage

func (c *Container) AddMessage(group node.Group, err *text.Message, setForFields ...string)

AddMessage adds the provided error, and if a non-empty names list is set, adds the error on the corresponding field.

func (*Container) GetNodes

func (c *Container) GetNodes() *node.Nodes

func (*Container) ParseError

func (c *Container) ParseError(group node.Group, err error) error

ParseError type asserts the given error and sets the container's errors or a field's errors and if the error is not something to be handled by the formUI Container, the error is returned.

This method DOES NOT touch the values of the node values/names, only its errors.

func (*Container) Reset

func (c *Container) Reset(exclude ...string)

Reset resets the container's errors as well as each field's value and errors.

func (*Container) ResetMessages

func (c *Container) ResetMessages(exclude ...string)

ResetMessages resets the container's own and its node's messages.

func (*Container) Scan

func (c *Container) Scan(value interface{}) error

func (*Container) SetCSRF

func (c *Container) SetCSRF(token string)

SetCSRF sets the CSRF value using e.g. nosurf.Token(r).

func (*Container) SetNode

func (c *Container) SetNode(n *node.Node)

SetNode sets a field.

func (*Container) SetValue

func (c *Container) SetValue(id string, n *node.Node)

SetValue sets a container's field to the provided name and value.

func (*Container) SortNodes

func (c *Container) SortNodes(ctx context.Context, opts ...node.SortOption) error

func (*Container) UnsetNode

func (c *Container) UnsetNode(id string)

Unset removes a field from the container.

func (*Container) UpdateNodeValuesFromJSON

func (c *Container) UpdateNodeValuesFromJSON(raw json.RawMessage, prefix string, group node.Group)

UpdateNodeValuesFromJSON sets the container's fields to the provided values.

func (*Container) Value

func (c *Container) Value() (driver.Value, error)

type ErrorParser

type ErrorParser interface {
	// ParseError type asserts the given error and sets the forms's errors or a
	// field's errors and if the error is not something to be handled by the
	// formUI Container itself, the error is returned for further propagation (e.g. showing a 502 status code).
	ParseError(group node.Group, err error) error
}

ErrorParser is capable of parsing and processing errors.

type FieldSorter

type FieldSorter interface {
	SortNodes(schemaRef string, prefix string, keysInOrder []string) error
}

type MessageResetter

type MessageResetter interface {
	// ResetMessages resets the messages recursively.
	ResetMessages(exclude ...string)
}

type NodeGetter

type NodeGetter interface {
	GetNodes() *node.Nodes
}

type NodeSetter

type NodeSetter interface {
	// SetNode sets (adds / replaces) a node.
	SetNode(field node.Node)
}

type NodeUnsetter

type NodeUnsetter interface {
	// UnsetFields removes a node.
	UnsetNode(name string)
}

type Resetter

type Resetter interface {
	// Resets all values and messages recursively.
	Reset(exclude ...string)
}

type ValueSetter

type ValueSetter interface {
	// SetValue sets a value the passed node.
	SetValue(name string, value *node.Node)
}

Jump to

Keyboard shortcuts

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