Documentation
¶
Index ¶
- Constants
- func CSRFFormFieldGenerator(g CSRFGenerator) func(r *http.Request) *Field
- type CSRFGenerator
- type CSRFSetter
- type ErrorParser
- type Field
- type FieldSetter
- type FieldSorter
- type FieldUnsetter
- type Fields
- type Form
- type HTMLForm
- func NewHTMLForm(action string) *HTMLForm
- func NewHTMLFormFromJSON(action string, raw json.RawMessage, prefix string) *HTMLForm
- func NewHTMLFormFromJSONSchema(action, jsonSchemaRef, prefix string, compiler *jsonschema.Compiler) (*HTMLForm, error)
- func NewHTMLFormFromRequestBody(r *http.Request, action string, compiler decoderx.HTTPDecoderOption) (*HTMLForm, error)
- func (c *HTMLForm) AddMessage(err *text.Message, setForFields ...string)
- func (c *HTMLForm) ParseError(err error) error
- func (c *HTMLForm) Reset(exclude ...string)
- func (c *HTMLForm) ResetMessages(exclude ...string)
- func (c *HTMLForm) Scan(value interface{}) error
- func (c *HTMLForm) SetCSRF(token string)
- func (c *HTMLForm) SetField(field Field)
- func (c *HTMLForm) SetRequired(fields ...string)
- func (c *HTMLForm) SetValue(name string, value interface{})
- func (c *HTMLForm) SetValues(values map[string]interface{})
- func (c *HTMLForm) SetValuesFromJSON(raw json.RawMessage, prefix string)
- func (c *HTMLForm) SortFields(schemaRef string) error
- func (c *HTMLForm) UnsetField(name string)
- func (c *HTMLForm) Value() (driver.Value, error)
- type MessageAdder
- type MessageResetter
- type Resetter
- type ValueSetter
Constants ¶
const CSRFTokenName = "csrf_token"
const DisableFormField = "disableFormField"
Variables ¶
This section is empty.
Functions ¶
func CSRFFormFieldGenerator ¶
func CSRFFormFieldGenerator(g CSRFGenerator) func(r *http.Request) *Field
Types ¶
type CSRFGenerator ¶
type CSRFSetter ¶
type CSRFSetter interface { // SetCSRF sets the CSRF value for the form. SetCSRF(string) }
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 // form itself, the error is returned for further propagation (e.g. showing a 502 status code). ParseError(err error) error }
ErrorParser is capable of parsing and processing errors.
type Field ¶
type Field struct { // Name is the equivalent of `<input name="{{.Name}}">` // // required: true Name string `json:"name"` // Type is the equivalent of `<input type="{{.Type}}">` // // required: true Type string `json:"type"` // Pattern is the equivalent of `<input pattern="{{.Pattern}}">` Pattern string `json:"pattern,omitempty"` // Disabled is the equivalent of `<input {{if .Disabled}}disabled{{end}}">` Disabled bool `json:"disabled,omitempty"` // Required is the equivalent of `<input required="{{.Required}}">` Required bool `json:"required,omitempty"` // Value is the equivalent of `<input value="{{.Value}}">` Value interface{} `json:"value,omitempty" faker:"string"` // Messages contains a list of messages (e.g. validation errors) that affect this field. Messages text.Messages `json:"messages,omitempty"` }
Field represents a HTML Form Field
swagger:model formField
type FieldSetter ¶
type FieldSetter interface { // SetField sets a field of the form. SetField(field Field) }
type FieldSorter ¶
type FieldUnsetter ¶
type FieldUnsetter interface { // UnsetFields removes a field from the form. UnsetField(name string) }
type Form ¶
type Form interface { ErrorParser FieldSetter ValueSetter FieldUnsetter MessageAdder CSRFSetter Resetter FieldSorter }
type HTMLForm ¶
type HTMLForm struct { sync.RWMutex `faker:"-"` // 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"` // Fields contains the form fields. // // required: true Fields Fields `json:"fields"` // Messages contains all global form messages and errors. Messages text.Messages `json:"messages,omitempty"` }
HTMLForm represents a HTML Form. The container can work with both HTTP Form and JSON requests
swagger:model form
func NewHTMLForm ¶
NewHTMLForm returns an empty container.
func NewHTMLFormFromJSON ¶
func NewHTMLFormFromJSON(action string, raw json.RawMessage, prefix string) *HTMLForm
NewHTMLFormFromJSON creates a HTML form based on the provided JSON struct.
func NewHTMLFormFromJSONSchema ¶
func NewHTMLFormFromJSONSchema(action, jsonSchemaRef, prefix string, compiler *jsonschema.Compiler) (*HTMLForm, error)
NewHTMLFormFromJSONSchema creates a new HTMLForm and populates the fields using the provided JSON Schema.
func NewHTMLFormFromRequestBody ¶
func NewHTMLFormFromRequestBody(r *http.Request, action string, compiler decoderx.HTTPDecoderOption) (*HTMLForm, error)
NewHTMLFormFromRequestBody creates a new HTMLForm and populates fields by parsing the HTTP Request body. A jsonSchemaRef needs to be added to allow HTTP Form Post Body parsing.
func (*HTMLForm) AddMessage ¶
AddMessage adds the provided error, and if a non-empty names list is set, adds the error on the corresponding field.
func (*HTMLForm) ParseError ¶
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 form container, the error is returned.
This method DOES NOT touch the values of the form fields, only its errors.
func (*HTMLForm) Reset ¶
Reset resets the container's errors as well as each field's value and errors.
func (*HTMLForm) ResetMessages ¶
Reset resets the container's errors as well as each field's value and errors.
func (*HTMLForm) SetRequired ¶
SetRequired sets the container's fields required.
func (*HTMLForm) SetValuesFromJSON ¶
func (c *HTMLForm) SetValuesFromJSON(raw json.RawMessage, prefix string)
SetValuesFromJSON sets the container's fields to the provided values.
func (*HTMLForm) SortFields ¶
func (*HTMLForm) UnsetField ¶
Unset removes a field from the container.
type MessageAdder ¶
type MessageResetter ¶
type MessageResetter interface { // ResetMessages resets the form's or field's messages.. ResetMessages(exclude ...string) }
type ValueSetter ¶
type ValueSetter interface { // SetValue sets a value of the form. SetValue(name string, value interface{}) }