Documentation ¶
Index ¶
- Constants
- func CSRFFormFieldGenerator(g CSRFGenerator) func(r *http.Request) *Field
- type CSRFGenerator
- type CSRFSetter
- type Error
- type ErrorAdder
- type ErrorParser
- type ErrorResetter
- type Errors
- type Field
- type FieldSetter
- type FieldSorter
- type FieldUnsetter
- type Fields
- 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) AddError(err *Error, names ...string)
- func (c *HTMLForm) ParseError(err error) error
- func (c *HTMLForm) Reset(exclude ...string)
- func (c *HTMLForm) ResetErrors(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, prefix string) error
- func (c *HTMLForm) UnsetField(name string)
- func (c *HTMLForm) Value() (driver.Value, error)
- 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 Error ¶
type Error struct { // Code FormErrorCode `json:"id,omitempty"` Message string `json:"message"` }
swagger:model formError
type ErrorAdder ¶
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 ErrorResetter ¶
type ErrorResetter interface { // ResetErrors resets errors. ResetErrors(exclude ...string) }
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 disabled="{{.Disabled}}">` 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:"name"` // Errors contains all validation errors this particular field has caused. Errors Errors `json:"errors,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 {
UnsetField(name string)
}
type HTMLForm ¶
type HTMLForm struct { sync.RWMutex // Action should be used as the form action URL `<form action="{{ .Action }}" method="post">`. // // required: true Action string `json:"action"` // Method is the form method (e.g. POST) // // required: true Method string `json:"method"` // Fields contains the form fields. // // required: true Fields Fields `json:"fields"` // Errors contains all form errors. These will be duplicates of the individual field errors. Errors []Error `json:"errors,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) AddError ¶
AddError 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) ResetErrors ¶
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 ValueSetter ¶
type ValueSetter interface { // SetValue sets a value of the form. SetValue(name string, value interface{}) }