Documentation ¶
Index ¶
- Variables
- func FormHTML(s interface{}, req *http.Request, htmlFunc HTMLFunc) *pongo2.Value
- func GridHTML(fi *FieldInfo, value string, req *http.Request, buf *bytes.Buffer)
- func InputHTML(fi *FieldInfo, value string, req *http.Request, buf *bytes.Buffer)
- type ErrorInfo
- type ErrorSink
- type Errors
- type FieldInfo
- type HTMLFunc
- type SelectValue
- type State
Constants ¶
This section is empty.
Variables ¶
var SelectValueFuncs = map[string]func(fi *FieldInfo, req *http.Request) []SelectValue{}
Obtains select values. The map is keyed by ValueSet. Return a list of values in the desired order.
Functions ¶
func FormHTML ¶
Generates HTML (as a pongo2 safe value) for the given form. The given function is used for field layout.
Types ¶
type ErrorInfo ¶
type ErrorInfo struct { // Field to which this error pertains. May be nil. FieldInfo *FieldInfo // Error message. Message string }
Represents a specific error with a form submission.
type Errors ¶
type Errors []*ErrorInfo
Represents zero or more errors with a form submission.
Implements ErrorSink.
type FieldInfo ¶
type FieldInfo struct { FName string // struct field name Name string // <input name="..." />. Defaults to ID or FName. Type string // <input type="..." /> (or "select" or "textarea"). Required bool // required="" Pattern string // pattern="..." (enforced on server as well) MaxLength int // 0: no max length Size int // field size. cols for textarea VSize int // rows for textarea FormatMessage string // validation error format message Classes []string // HTML classes ID string // HTML ID Autofocus bool // <input autofocus="" /> Placeholder string // <input placeholder="..." /> Label string // Label text ValueSet string // <select> value set. }
Information about a form field.
func GetFieldInfo ¶
func GetFieldInfo(sf reflect.StructField) FieldInfo
Get the information for a struct field.
The format is as follows:
Field SomeType `form:"TYPE[,required][,autofocus][,.htmlClass][,#htmlID][,<int>][,<int>!]"`
The integer tag expresses a field size. The integer tag with "!" expresses a maximum length.
TYPE is the HTML field type. For non-<input/> types, use the tag name ("select", "textarea", etc.)
Many HTML classes may be specified. If the HTML ID is not specified, the struct field name is used as the field name and HTML ID. Otherwise, the HTML ID is used as the field name and HTML ID.
The following additional field tags are also supported:
fmsg: Format message, shown on validation error. pattern: Regexp to enforce on client and server. placeholder: Placeholder string. label: Label string. set: <select> value set.
type SelectValue ¶
type SelectValue struct { // The actual value of the option sent to the server. Value string // The label shown to the user. Title string // Optgroup. Values in the same optgroup must be contiguous. Optgroups // cannot be nested. Values with a Group of "" are outside any optgroup. Group string // Should the option be disabled? Disabled bool }
An option for a <select> field.