fields

package
v0.0.0-...-c4682c2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2014 License: BSD-3-Clause Imports: 5 Imported by: 3

Documentation

Overview

Package goforms/fields provides various types of fields for validating and cleaning individual form values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseField

type BaseField struct {
	Required bool
	Array    bool
}

The types that are embedded/shared with more specific field types.

func (BaseField) CleanArray

func (f BaseField) CleanArray([]string) (interface{}, ValidationError)

Returns true if this field support array.

func (BaseField) IsArray

func (f BaseField) IsArray() bool

Returns true if this field support array.

func (BaseField) IsRequired

func (f BaseField) IsRequired() bool

Returns whether data for this field is required.

type BoolField

type BoolField struct {
	BaseField
}

func NewBoolField

func NewBoolField(defaults Defaults) BoolField

Create and initialise the new fields with the given defaults.

func (BoolField) Clean

func (f BoolField) Clean(value string) (interface{}, ValidationError)

Check whether the given string value is valid for this field and return the cleaned value or a relevant error.

type CharField

type CharField struct {
	BaseField
	Max int
	Min int
}

func NewCharField

func NewCharField(defaults Defaults) CharField

Create and initialise the new fields with the given defaults.

func NewJSONField

func NewJSONField(defaults Defaults) CharField

Create and initialise the new fields with the given defaults.

func (CharField) Clean

func (f CharField) Clean(value string) (interface{}, ValidationError)

Check whether the given string value is valid for this field and return the cleaned value or a relevant error.

type Defaults

type Defaults map[string]interface{}

Specify the default attributes of a field.

type Field

type Field interface {
	Clean(string) (interface{}, ValidationError)
	CleanArray([]string) (interface{}, ValidationError)
	IsRequired() bool
	IsArray() bool
}

A field is able to clean a string value to the correct type or indicate a relevant error, as well as determine whether it is required.

type IntegerField

type IntegerField struct {
	BaseField
}

func NewIntegerField

func NewIntegerField(defaults Defaults) IntegerField

Create and initialise the new fields with the given defaults.

func (IntegerField) Clean

func (f IntegerField) Clean(value string) (interface{}, ValidationError)

Check whether the given string value is valid for this field and return the cleaned value or a relevant error.

func (IntegerField) IsRequired

func (f IntegerField) IsRequired() bool

type JSONField

type JSONField struct {
	BaseField
}

func (JSONField) Clean

func (f JSONField) Clean(value string) (interface{}, ValidationError)

Check whether the given string value is valid for this field and return the cleaned value or a relevant error.

type RegexField

type RegexField struct {
	BaseField
	MatchString string
	Max         int
	Min         int
}

func NewRegexField

func NewRegexField(defaults Defaults) RegexField

Create and initialise the new fields with the given defaults.

func (RegexField) Clean

func (f RegexField) Clean(value string) (interface{}, ValidationError)

Check whether the given string value is valid for this field and return the cleaned value or a relevant error.

type ValidationError

type ValidationError interface {
	Error() string
}

Jump to

Keyboard shortcuts

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