Documentation ¶
Index ¶
- type Attributes
- type Checkbox
- type Choice
- type Data
- type Email
- type Field
- type Form
- type InSlice
- type Input
- type InputDate
- type InputDateTime
- type InputEmail
- type InputMonth
- type InputNumber
- type InputPassword
- type InputSearch
- type InputTel
- type InputTime
- type InputURL
- type InputWeek
- type MaxLength
- type MinLength
- type Radio
- type Regexp
- type Required
- type Textarea
- type Type
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attributes ¶
type Attributes map[string]interface{}
Attributes is structure that contains forms or fields attributes
type Checkbox ¶
type Checkbox struct {
*Input
}
Checkbox is checkbox input type
type Choice ¶
Choice is used to store choices in field I choose to use type here because we need ordering of choices
type Data ¶
type Data map[string]interface{}
Data is structure in which we store cleaned and initial data
type Field ¶
type Field struct { Name string Label string LabelAttributes Attributes Choices []Choice Value []string InitialValue interface{} Type Type Attributes Attributes Validators []Validator Errors []string }
Field represent single field in form and its validatorss
func (*Field) HasErrors ¶
HasErrors returns information if there are validation errors in this field
func (*Field) Render ¶
Render field (in matter of fact, only passing through to render method on type)
func (*Field) RenderErrors ¶
RenderErrors render all errors as list (<ul>) with class "errors"
type Form ¶
type Form struct { // Keeps all the fields Fields map[string]*Field // Form attributes Attributes Attributes // Data that are used in validation IncomingData url.Values // After validation is done we put data here CleanedData Data // Initial data are used before form validation InitialData Data }
Form is structure that hold all fields, data, and
func New ¶
func New(fields map[string]*Field, attrs Attributes) *Form
New is shorthand, and preferred way, to create new form. Main difference is that, this approach add field name, basing on key in map, to a field instance Example
form := forms.New( map[string]*forms.Field{ "field1": &forms.Field{}, "field2": &forms.Field{}, }, forms.Attributes{"id": "test"}, )
func (*Form) IsValid ¶
IsValid validate all fields and if all is correct assign cleaned data from every field to forms CleanedData attribute
func (*Form) IsValidMap ¶
IsValidMap populates data from map. It accepts map of string/strings with keys as field names.
type InSlice ¶
type InSlice struct {
Values []string
}
InSlice validator checks if given value is in slice
validator := &MaxLength{[]string{"ham", "spam", "eggs"}]}
type Input ¶
type Input struct{}
Input is basic input type
func (*Input) IsMultiValue ¶
IsMultiValue returns if basic input allow multiple values
type InputDateTime ¶
type InputDateTime struct {
*Input
}
InputDateTime is date datetime (uses datetime-local) input type
type InputNumber ¶
type InputNumber struct{}
InputNumber is number input type
func (*InputNumber) CleanData ¶
func (t *InputNumber) CleanData(values []string) interface{}
CleanData returns cleaned values for number input
func (*InputNumber) IsMultiValue ¶
func (t *InputNumber) IsMultiValue() bool
IsMultiValue returns if numeric input allow multiple values
type MaxLength ¶
type MaxLength struct {
Max int
}
MaxLength validator checks if given values length doesn't exceed given value
validator := &MaxLength{32}
type MinLength ¶
type MinLength struct {
Min int
}
MinLength validator checks if given values length is under value
validator := &MaxLength{32}
type Radio ¶
type Radio struct{}
Radio is radio input type
func (*Radio) IsMultiValue ¶
IsMultiValue returns if radio input allow multiple values
type Regexp ¶
type Regexp struct {
Pattern string
}
Regexp validator checks if given value match pattern
validator := &Regexp{"\d{4}.\d{2}.\d{2} \d{2}:\d{2}:\d{2}"}