Documentation ¶
Index ¶
- Variables
- func CheckboxMultipleWidget(attrs map[string]string, mk CheckboxOptionsMaker) *checkboxMultipleWidget
- func EmailValidator(message ...string) regexpValidator
- func MaxLengthValidator(length int, message ...string) maxLengthValidator
- func MaxValueValidator(value int, message ...string) maxValueValidator
- func MinLengthValidator(length int, message ...string) minLengthValidator
- func MinValueValidator(value int, message ...string) minValueValidator
- func RadioSelectWidget(attrs map[string]string, mk RadioOptionsMaker) *radioSelectWidget
- func RegexpValidator(regex string, message ...string) regexpValidator
- func Required(message ...string) required
- func SelectMultipleWidget(attrs map[string]string, mk SelectOptionsMaker) *selectWidget
- func SelectWidget(attrs map[string]string, mk SelectOptionsMaker) *selectWidget
- func URLValidator(message ...string) regexpValidator
- type BaseField
- type BooleanField
- type BooleanFieldInstance
- type CheckboxContext
- type CheckboxOptions
- type CheckboxOptionsMaker
- type CleanedData
- type Data
- type DateTimeField
- type DateTimeFieldInstance
- type Errors
- type Field
- type FieldContext
- type FieldInstance
- func (f *FieldInstance) Errors() []string
- func (f *FieldInstance) GetModel() Field
- func (f *FieldInstance) GetName() string
- func (f *FieldInstance) GetV() *V
- func (f *FieldInstance) GetWidget() Widget
- func (f *FieldInstance) HasError() bool
- func (f *FieldInstance) SetErrors(errs []string)
- func (f *FieldInstance) SetInitial(v string)
- func (f *FieldInstance) Validate(fo *FormInstance) []string
- type FieldInterface
- type FieldInterfaces
- type Fields
- type FloatField
- type FloatFieldInstance
- type Form
- type FormInstance
- type IntegerField
- type IntegerFieldInstance
- type ModelContext
- type ModelForm
- type ModelFormInstance
- type MultipleTextField
- type MultipleTextFieldInstance
- type RadioOptions
- type RadioOptionsMaker
- type SelectOptions
- type SelectOptionsMaker
- type StringCheckboxOptions
- type StringRadioOptions
- type StringSelectOptions
- type TextField
- type TextFieldInstance
- type V
- type Validator
- type Validators
- type Widget
Constants ¶
This section is empty.
Variables ¶
var DefaultDateFormat string = "2006-01-02"
var DefaultDateTimeFormat string = "2006-01-02 15:04:05"
var Template *template.Template
all templates of Field and Widget
Functions ¶
func CheckboxMultipleWidget ¶
func CheckboxMultipleWidget(attrs map[string]string, mk CheckboxOptionsMaker) *checkboxMultipleWidget
Generate checkbox input field: <input type="checkbox" ...>
func EmailValidator ¶
func EmailValidator(message ...string) regexpValidator
An EmailValidator that ensures a value looks like an email address.
func MaxLengthValidator ¶
Returns error if the length of value is greater than length argument.
func MaxValueValidator ¶
func MinLengthValidator ¶
Returns error if the length of value is less than length argument.
func MinValueValidator ¶
func RadioSelectWidget ¶
func RadioSelectWidget(attrs map[string]string, mk RadioOptionsMaker) *radioSelectWidget
Generate radio input field: <input type="radio" ...>
func RegexpValidator ¶
The regular expression pattern to search for the provided value. Returns error if regxp#MatchString is False.
func Required ¶
func Required(message ...string) required
Returns error if the field is not provided.
func SelectMultipleWidget ¶
func SelectMultipleWidget(attrs map[string]string, mk SelectOptionsMaker) *selectWidget
Generate select-multiple and options field: <select multiple><option></option></select>
func SelectWidget ¶
func SelectWidget(attrs map[string]string, mk SelectOptionsMaker) *selectWidget
Generate select and options field: <select><option></option></select>
func URLValidator ¶
func URLValidator(message ...string) regexpValidator
An URLValidator that ensures a value looks like an url.
Types ¶
type BaseField ¶
type BaseField struct { Field // contains filtered or unexported fields }
func (*BaseField) GetValidators ¶
func (f *BaseField) GetValidators() Validators
type BooleanField ¶
type BooleanField struct {
BaseField
}
It maps value to FormInstance.CleanedData as type `bool`.
func NewBooleanField ¶
func NewBooleanField(name string, vs Validators, ws ...Widget) *BooleanField
Create a new BooleanField with validators and widgets.
func (*BooleanField) New ¶
func (f *BooleanField) New() FieldInterface
Create a new BooleanField instance.
type BooleanFieldInstance ¶
type BooleanFieldInstance struct {
FieldInstance
}
Instance for BooleanField.
func (*BooleanFieldInstance) Clean ¶
func (f *BooleanFieldInstance) Clean(data Data) error
Get a value from request data, and clean it as type `bool`.
func (*BooleanFieldInstance) Html ¶
func (f *BooleanFieldInstance) Html() string
Get as HTML format.
type CheckboxContext ¶
type CheckboxContext struct { Field FieldInterface Attrs map[string]string Options checkboxOptionValues }
type CheckboxOptions ¶
type CheckboxOptionsMaker ¶
type CheckboxOptionsMaker func() CheckboxOptions
type DateTimeField ¶
It maps value to FormInstance.CleanedData as type `time.Time`.
func NewDateTimeField ¶
func NewDateTimeField(name string, format string, vs Validators, ws ...Widget) *DateTimeField
Create a new DateTimeField with validators and widgets.
func (*DateTimeField) New ¶
func (f *DateTimeField) New() FieldInterface
Create a new DateField instance.
type DateTimeFieldInstance ¶
type DateTimeFieldInstance struct { FieldInstance Format string ErrorMessage string }
Instance for DateTimeField
func (*DateTimeFieldInstance) Clean ¶
func (f *DateTimeFieldInstance) Clean(data Data) error
Get a value from request data, and clean it as type string
func (*DateTimeFieldInstance) Html ¶
func (f *DateTimeFieldInstance) Html() string
type Field ¶
type Field interface { New() FieldInterface // Get field name GetName() string GetWidget() Widget GetValidators() Validators }
type FieldInstance ¶
type FieldInstance struct { Model Field V *V FieldInterface // contains filtered or unexported fields }
func (*FieldInstance) Errors ¶
func (f *FieldInstance) Errors() []string
func (*FieldInstance) GetModel ¶
func (f *FieldInstance) GetModel() Field
func (*FieldInstance) GetName ¶
func (f *FieldInstance) GetName() string
func (*FieldInstance) GetV ¶
func (f *FieldInstance) GetV() *V
func (*FieldInstance) GetWidget ¶
func (f *FieldInstance) GetWidget() Widget
func (*FieldInstance) HasError ¶
func (f *FieldInstance) HasError() bool
func (*FieldInstance) SetErrors ¶
func (f *FieldInstance) SetErrors(errs []string)
func (*FieldInstance) SetInitial ¶
func (f *FieldInstance) SetInitial(v string)
func (*FieldInstance) Validate ¶
func (f *FieldInstance) Validate(fo *FormInstance) []string
type FieldInterface ¶
type FieldInterfaces ¶
type FieldInterfaces struct {
// contains filtered or unexported fields
}
type FloatField ¶
It maps value to FormInstance.CleanedData as type `float64`.
func NewFloatField ¶
func NewFloatField(name string, vs Validators, ws ...Widget) *FloatField
Create a new FloatField with validators and widgets.
func (*FloatField) New ¶
func (f *FloatField) New() FieldInterface
Create a new FloatField instance.
type FloatFieldInstance ¶
type FloatFieldInstance struct { FieldInstance ErrorMessage string }
Instance for FloatField
func (*FloatFieldInstance) Clean ¶
func (f *FloatFieldInstance) Clean(data Data) error
Get a value from request data, and clean it as type float64.
type Form ¶
type Form func(...*http.Request) *FormInstance
func (Form) FromRequest ¶
func (f Form) FromRequest(r *http.Request) *FormInstance
Create a new form instance from `http.Request`.
func (Form) FromUrlValues ¶
func (f Form) FromUrlValues(uv url.Values) *FormInstance
Create a new form instance from `url.Values`.
type FormInstance ¶
type FormInstance struct { Data Data CleanedData CleanedData ParseError error // contains filtered or unexported fields }
FormInstance made by Form.
func (*FormInstance) Errors ¶
func (f *FormInstance) Errors() Errors
Return field errors if any fields have error after calling `FormInstance#IsValid`.
func (*FormInstance) Fields ¶
func (f *FormInstance) Fields() []FieldInterface
Get all `FieldInstance` on `FormInstance`.
func (*FormInstance) GetField ¶
func (f *FormInstance) GetField(name string) (FieldInterface, bool)
Get a `FieldInterface` for the given field name.
func (*FormInstance) IsValid ¶
func (f *FormInstance) IsValid() bool
Validation request data. If any fields have errors, this method returns false.
func (*FormInstance) MapTo ¶
func (fi *FormInstance) MapTo(model interface{})
maps cleanedData to specified model.
type IntegerField ¶
It maps value to FormInstance.CleanedData as type `int`.
func NewIntegerField ¶
func NewIntegerField(name string, vs Validators, ws ...Widget) *IntegerField
Create a new IntegerField with validators and widgets.
func (*IntegerField) New ¶
func (f *IntegerField) New() FieldInterface
Create a new IntegerField instance.
type IntegerFieldInstance ¶
type IntegerFieldInstance struct { FieldInstance ErrorMessage string }
Instance for IntegerField
func (*IntegerFieldInstance) Clean ¶
func (f *IntegerFieldInstance) Clean(data Data) error
Get a value from request data, and clean it as type `int`.
func (*IntegerFieldInstance) Html ¶
func (f *IntegerFieldInstance) Html() string
Get as HTML format.
type ModelContext ¶
type ModelContext struct { ModelType reflect.Type FieldContexts []FieldContext }
type ModelForm ¶
type ModelForm func(...*http.Request) *ModelFormInstance
func DefineModelForm ¶
Define a new form with generating fields from model's attributes and specified fields.
type ModelFormInstance ¶
type ModelFormInstance struct { FormInstance ModelContext }
func (*ModelFormInstance) GetModel ¶
func (mfi *ModelFormInstance) GetModel() interface{}
type MultipleTextField ¶
type MultipleTextField struct {
BaseField
}
It maps value to FormInstance.CleanedData as type `[]string`.
func NewMultipleTextField ¶
func NewMultipleTextField(name string, vs Validators, ws ...Widget) *MultipleTextField
Create a new MultipleTextField with validators and widgets.
func (*MultipleTextField) New ¶
func (f *MultipleTextField) New() FieldInterface
Create a new MultipleField instance.
type MultipleTextFieldInstance ¶
type MultipleTextFieldInstance struct {
FieldInstance
}
Instance for MultipleTextField.
func (*MultipleTextFieldInstance) Clean ¶
func (f *MultipleTextFieldInstance) Clean(data Data) error
Get a value from request data, and clean it as type `[]string`.
func (*MultipleTextFieldInstance) Html ¶
func (f *MultipleTextFieldInstance) Html() string
Get as HTML format.
type RadioOptions ¶
type RadioOptionsMaker ¶
type RadioOptionsMaker func() RadioOptions
type SelectOptions ¶
type SelectOptionsMaker ¶
type SelectOptionsMaker func() SelectOptions
type StringCheckboxOptions ¶
type StringCheckboxOptions [][]string
func (StringCheckboxOptions) Checked ¶
func (opt StringCheckboxOptions) Checked(i int) bool
func (StringCheckboxOptions) Disabled ¶
func (opt StringCheckboxOptions) Disabled(i int) bool
func (StringCheckboxOptions) Label ¶
func (opt StringCheckboxOptions) Label(i int) string
func (StringCheckboxOptions) Len ¶
func (opt StringCheckboxOptions) Len() int
func (StringCheckboxOptions) Value ¶
func (opt StringCheckboxOptions) Value(i int) string
type StringRadioOptions ¶
type StringRadioOptions [][]string
func (StringRadioOptions) Checked ¶
func (opt StringRadioOptions) Checked(i int) bool
func (StringRadioOptions) Disabled ¶
func (opt StringRadioOptions) Disabled(i int) bool
func (StringRadioOptions) Label ¶
func (opt StringRadioOptions) Label(i int) string
func (StringRadioOptions) Len ¶
func (opt StringRadioOptions) Len() int
func (StringRadioOptions) Value ¶
func (opt StringRadioOptions) Value(i int) string
type StringSelectOptions ¶
type StringSelectOptions [][]string
func (StringSelectOptions) Disabled ¶
func (opt StringSelectOptions) Disabled(i int) bool
func (StringSelectOptions) Label ¶
func (opt StringSelectOptions) Label(i int) string
func (StringSelectOptions) Len ¶
func (cs StringSelectOptions) Len() int
func (StringSelectOptions) Selected ¶
func (opt StringSelectOptions) Selected(i int) bool
func (StringSelectOptions) Value ¶
func (opt StringSelectOptions) Value(i int) string
type TextField ¶
type TextField struct {
BaseField
}
It maps value to FormInstance.CleanedData as type `string`.
func NewTextField ¶
func NewTextField(name string, vs Validators, ws ...Widget) *TextField
Create a new TextField with validators and widgets.
type TextFieldInstance ¶
type TextFieldInstance struct {
FieldInstance
}
Instance for TextField
func (*TextFieldInstance) Clean ¶
func (f *TextFieldInstance) Clean(data Data) error
Get a value from request data, and clean it as type `string`.
type Validator ¶
type Validator interface { Name() string Validate(*FieldInstance, *FormInstance) error }
type Validators ¶
type Validators []Validator
type Widget ¶
type Widget interface {
// contains filtered or unexported methods
}
Interface for all widgets.
func HiddenInputWidget ¶
Generate hidden input field: <input type="hidden" ...>
func PasswordInputWidget ¶
Generate password input field: <input type="password" ...>
func TextAreaWidget ¶
Generate text area fiele: <extarea ...>
func TextInputWidget ¶
Generate text input fiele: <input type="text" ...>
Source Files ¶
- baseinput_widget.go
- binding.go
- booleanfield.go
- checkboxwidget.go
- datetimefield.go
- errors.go
- fields.go
- floatfield.go
- forms.go
- helpers.go
- hiddeninputwidget.go
- integerfield.go
- modelforms.go
- multipletextfield.go
- passwordinputwidget.go
- radiowidget.go
- selectwidget.go
- templates.go
- textfield.go
- textinputwidget.go
- validators.go
- values.go
- widgets.go