Documentation ¶
Overview ¶
Package h provides utilties for rendering HTML forms.
Index ¶
- func MustBeAbsolutePath(val string) error
- func MustBePosixAccountName(val string) error
- func MustBePosixUIDorGID(val string) error
- func MustNotBeEmpty(val string) error
- func MustNotHaveSurroundingSpaces(val string) error
- type FieldSet
- type FieldState
- type FormField
- type FormSpec
- type FormState
- type InputFieldSpec
- type SelectFieldSpec
- type SelectOptionSpec
- type Snippet
- type StaticField
- type ValidationRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustBeAbsolutePath ¶
MustBeAbsolutePath is a ValidationRule.
func MustBePosixAccountName ¶
MustBePosixAccountName is a ValidationRule.
func MustBePosixUIDorGID ¶
MustBePosixUIDorGID is a ValidationRule.
func MustNotHaveSurroundingSpaces ¶
MustNotHaveSurroundingSpaces is a ValidationRule.
Types ¶
type FieldSet ¶
FieldSet is a FormField that groups multiple FormFields together.
type FieldState ¶
type FieldState struct { Value string //only used by InputFieldSpec Selected map[string]bool //only used by SelectFieldSpec IsUnfolded bool //only used by FieldSet ErrorMessage string }
FieldState describes the state of an <input> field within type FormState.
type FormField ¶
type FormField interface { ReadState(*http.Request, *FormState) RenderField(FormState) template.HTML }
FormField is something that can appear in an HTML form.
type FormSpec ¶
FormSpec describes an HTML form that is submitted to a POST endpoint.
type FormState ¶
type FormState struct {
Fields map[string]*FieldState
}
FormState describes the state of an HTML form.
type InputFieldSpec ¶
type InputFieldSpec struct { Name string Label string InputType string AutoFocus bool AutocompleteMode string Rules []ValidationRule }
InputFieldSpec describes a single <input> field within type FormSpec.
func (InputFieldSpec) ReadState ¶
func (f InputFieldSpec) ReadState(r *http.Request, formState *FormState)
ReadState reads and validates the field value from r.PostForm, and stores it in the given FormState.
func (InputFieldSpec) RenderField ¶
func (f InputFieldSpec) RenderField(state FormState) template.HTML
RenderField produces the HTML for this field.
type SelectFieldSpec ¶
type SelectFieldSpec struct { Name string Label string Options []SelectOptionSpec ReadOnly bool }
SelectFieldSpec is a FormField where values can be selected from a given set. It's rendered as a series of checkboxes.
func (SelectFieldSpec) ReadState ¶
func (f SelectFieldSpec) ReadState(r *http.Request, formState *FormState)
ReadState implements the FormField interface.
func (SelectFieldSpec) RenderField ¶
func (f SelectFieldSpec) RenderField(state FormState) template.HTML
RenderField implements the FormField interface.
type SelectOptionSpec ¶
SelectOptionSpec describes an option that can be selected in a SelectFieldSpec.
type Snippet ¶
Snippet provides a convenience API around html/template.Template.
func NewSnippet ¶
NewSnippet parses html/template code into a Snippet.
type StaticField ¶
StaticField is a FormField with a static value.
func (StaticField) ReadState ¶
func (f StaticField) ReadState(*http.Request, *FormState)
ReadState implements the FormField interface.
func (StaticField) RenderField ¶
func (f StaticField) RenderField(FormState) template.HTML
RenderField implements the FormField interface.
type ValidationRule ¶
ValidationRule returns an error message if the given field value is invalid.