forms

package
v0.0.0-...-5dbc853 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2015 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmailFormat   = errors.New("please enter a valid email address")
	ErrPasswordLen   = errors.New(fmt.Sprintf("please enter a password with at least %d characters", passwordMinLen))
	ErrPasswordSpace = errors.New("please enter a password without any space")
	ErrPhoneFormat   = errors.New("please enter a valid phone number")
	ErrNameFormat    = errors.New("please enter a valid name")
	ErrStringValue   = errors.New("invalid string value")
	ErrIntValue      = errors.New("invalid int value")
)
View Source
var CapFormatter = FormatterFunc(func(rawValue string) string {
	return strings.Title(strings.ToLower(rawValue))
})
View Source
var (
	ErrNotANumber = errors.New("not a number")
)
View Source
var IntLoader = LoaderFunc(func(rawValue string) (interface{}, error) {
	val, err := strconv.ParseInt(rawValue, 0, 0)
	if err != nil {
		return nil, ErrNotANumber
	}
	return int(val), nil
})
View Source
var StringLoader = LoaderFunc(func(rawValue string) (interface{}, error) {
	return strings.TrimSpace(rawValue), nil
})

Functions

This section is empty.

Types

type Field

type Field struct {
	Name string
	// contains filtered or unexported fields
}

func (*Field) Validate

func (f *Field) Validate(rawValue string) (interface{}, error)

type FieldBuilder

type FieldBuilder struct {
	// contains filtered or unexported fields
}

func (*FieldBuilder) Build

func (fb *FieldBuilder) Build() *Field

func (*FieldBuilder) Empty

func (fb *FieldBuilder) Empty(value interface{}) *FieldBuilder

func (*FieldBuilder) Loader

func (fb *FieldBuilder) Loader(loader LoaderFunc) *FieldBuilder

func (*FieldBuilder) Required

func (fb *FieldBuilder) Required() *FieldBuilder

func (*FieldBuilder) WithFormatters

func (fb *FieldBuilder) WithFormatters(formatters ...FormatterFunc) *FieldBuilder

func (*FieldBuilder) WithValidators

func (fb *FieldBuilder) WithValidators(validators ...ValidatorFunc) *FieldBuilder

type Form

type Form struct {
	Fields     map[string]*Field
	FieldNames []string
	Errors     map[string]error
	Values     FormValues
	// contains filtered or unexported fields
}

func New

func New() *Form

func (*Form) ConsolidateErrors

func (f *Form) ConsolidateErrors() chatable.FormError

func (*Form) Valid

func (f *Form) Valid(postForm url.Values) bool

Valid validates each field followed by the form's validator if provided.

func (*Form) WithField

func (f *Form) WithField(name string, fb *FieldBuilder) *Form

WithField adds the Field produced by the FieldBuilder to the Form under the given name.

func (*Form) WithValidator

func (f *Form) WithValidator(validator FormValidator) *Form

WithValidator adds the FormValidator to the form.

type FormValidator

type FormValidator func(formValues *FormValues) bool

type FormValues

type FormValues map[string]interface{}

type FormatterFunc

type FormatterFunc func(string) string

type LoaderFunc

type LoaderFunc func(string) (interface{}, error)

func NewTimeLoader

func NewTimeLoader(layout string) LoaderFunc

type ValidatorFunc

type ValidatorFunc func(interface{}) error

func EmailValidator

func EmailValidator() ValidatorFunc

func NameValidator

func NameValidator() ValidatorFunc

func PasswordValidator

func PasswordValidator() ValidatorFunc

func PhoneNumberValidator

func PhoneNumberValidator() ValidatorFunc

func RangeValidator

func RangeValidator(min, max int, errorMsg string) ValidatorFunc

func ReValidator

func ReValidator(pattern string, errorMsg string) ValidatorFunc

func UsernameValidator

func UsernameValidator() ValidatorFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL