form

package
v0.0.0-...-9e9b37c Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultText = Text{
	ErrorRequired:       "This field is required",
	ErrorTooLong:        "This value is too long",
	ErrorTooShort:       "This value is too short",
	ErrorInvalidEmail:   "This is not a valid e-mail address",
	ErrorInvalidWebsite: "This is not a valid website address",
	ErrorInvalidDate:    "This is not a valid date (expected YYYY-MM-DD)",
	ErrorValueBelowMin:  "The minimum accepted value is %v",
	ErrorValueAboveMax:  "The maximum accepted value is %v",
}

DefaultText is the default texts used by the package

View Source
var XSRFTokenGenerator = func(c *web.Context, seed int64) string {
	return ""
}
View Source
var XSRFTokenValidTime = time.Hour

Functions

func Complete

func Complete(c *web.Context, form interface{}, texts *Text) bool

Complete checks if the current request is a POST, and if so binds all form.Fields from the given form

func GetXSRFToken

func GetXSRFToken(c *web.Context) string

func IsXSRFTokenValid

func IsXSRFTokenValid(c *web.Context, token string) bool

Types

type CheckboxField

type CheckboxField struct {
	// configurable by user
	Name        string
	Caption     string
	Required    bool
	Description string
	Attributes  map[string]string

	// readable value
	Error string
	Value bool
}

func (*CheckboxField) Bind

func (t *CheckboxField) Bind(c *web.Context, texts *Text)

func (*CheckboxField) GetRenderDetails

func (t *CheckboxField) GetRenderDetails() (name, desc, caption, err string)

func (*CheckboxField) HTML

func (t *CheckboxField) HTML() template.HTML

func (*CheckboxField) Render

func (t *CheckboxField) Render(buffer *bytes.Buffer)

func (*CheckboxField) RowHTML

func (t *CheckboxField) RowHTML() template.HTML

func (*CheckboxField) SetAttribute

func (t *CheckboxField) SetAttribute(key, value string)

type DateTimeField

type DateTimeField struct {
	// configurable by user
	Type        DateTimeInputType
	Name        string
	Caption     string
	Required    bool
	Description string
	MinDate     *time.Time
	MaxDate     *time.Time
	Placeholder *time.Time
	Attributes  map[string]string

	// readable value
	Error string
	Value *time.Time
}

func (*DateTimeField) Bind

func (t *DateTimeField) Bind(c *web.Context, texts *Text)

func (*DateTimeField) GetRenderDetails

func (t *DateTimeField) GetRenderDetails() (name, desc, caption, err string)

func (*DateTimeField) HTML

func (t *DateTimeField) HTML() template.HTML

func (*DateTimeField) Render

func (t *DateTimeField) Render(buffer *bytes.Buffer)

func (*DateTimeField) RowHTML

func (t *DateTimeField) RowHTML() template.HTML

func (*DateTimeField) SetAttribute

func (t *DateTimeField) SetAttribute(key, value string)

type DateTimeInputType

type DateTimeInputType int
const (
	DateTimeInputDateTimeLocal DateTimeInputType = iota
	DateTimeInputDate
	DateTimeInputTime
)

type Field

type Field interface {
	Bind(c *web.Context, texts *Text)
	SetAttribute(name, value string)
	Render(buffer *bytes.Buffer)
	GetRenderDetails() (name, desc, caption, err string)
}

func GetFields

func GetFields(form interface{}) []Field

GetFields reflects over the form and finds the Fields

type FileField

type FileField struct {
	// configurable by user
	Name        string
	Caption     string
	Required    bool
	Description string
	Attributes  map[string]string

	// readable value
	Error string
	Value *UploadedFile
}

func (*FileField) Bind

func (t *FileField) Bind(c *web.Context, texts *Text)

func (*FileField) GetRenderDetails

func (t *FileField) GetRenderDetails() (name, desc, caption, err string)

func (*FileField) HTML

func (t *FileField) HTML() template.HTML

func (*FileField) Render

func (t *FileField) Render(buffer *bytes.Buffer)

func (*FileField) RowHTML

func (t *FileField) RowHTML() template.HTML

func (*FileField) SetAttribute

func (t *FileField) SetAttribute(key, value string)

type InputField

type InputField struct {
	// configurable by user
	Type        InputType
	Name        string
	Caption     string
	Required    bool
	Description string
	MaxLength   int
	MinLength   int
	Regexp      *regexp.Regexp
	RegexpError string
	Placeholder string
	Attributes  map[string]string

	// readable value
	Error string
	Value string
}

func (*InputField) Bind

func (t *InputField) Bind(c *web.Context, texts *Text)

func (*InputField) GetRenderDetails

func (t *InputField) GetRenderDetails() (name, desc, caption, err string)

func (*InputField) HTML

func (t *InputField) HTML() template.HTML

func (*InputField) Render

func (t *InputField) Render(buffer *bytes.Buffer)

func (*InputField) RowHTML

func (t *InputField) RowHTML() template.HTML

func (*InputField) SetAttribute

func (t *InputField) SetAttribute(key, value string)

type InputType

type InputType int
const (
	InputTypeText InputType = iota
	InputTypeTextArea
	InputTypeHidden
	InputTypePassword
	InputTypeEmail
	InputTypeWebsite
	InputTypeDate
)

type MultiCheckbox

type MultiCheckbox struct {
	// configurable by user
	Name        string
	Caption     string
	Description string
	Options     []*Option
	Attributes  map[string]string

	// readable value
	Error string
	Value interface{}
}

func (*MultiCheckbox) Bind

func (t *MultiCheckbox) Bind(c *web.Context, texts *Text)

func (*MultiCheckbox) GetRenderDetails

func (t *MultiCheckbox) GetRenderDetails() (name, desc, caption, err string)

func (*MultiCheckbox) HTML

func (t *MultiCheckbox) HTML() template.HTML

func (*MultiCheckbox) Render

func (t *MultiCheckbox) Render(buffer *bytes.Buffer)

func (*MultiCheckbox) RowHTML

func (t *MultiCheckbox) RowHTML() template.HTML

func (*MultiCheckbox) SetAttribute

func (t *MultiCheckbox) SetAttribute(key, value string)

type NumberField

type NumberField struct {
	// configurable by user
	Name        string
	Caption     string
	Required    bool
	Description string
	Min         *int64
	Max         *int64
	Placeholder string
	Attributes  map[string]string

	// readable value
	Error string
	Value *int64
}

func (*NumberField) Bind

func (t *NumberField) Bind(c *web.Context, texts *Text)

func (*NumberField) GetRenderDetails

func (t *NumberField) GetRenderDetails() (name, desc, caption, err string)

func (*NumberField) HTML

func (t *NumberField) HTML() template.HTML

func (*NumberField) Render

func (t *NumberField) Render(buffer *bytes.Buffer)

func (*NumberField) RowHTML

func (t *NumberField) RowHTML() template.HTML

func (*NumberField) SetAttribute

func (t *NumberField) SetAttribute(key, value string)

func (*NumberField) ValueNoNil

func (t *NumberField) ValueNoNil() int64

type Option

type Option struct {
	Caption string
	Name    string
	Value   interface{}
}

type SelectField

type SelectField struct {
	// configurable by user
	Name        string
	Caption     string
	Required    bool
	Description string
	Options     []*Option
	Attributes  map[string]string

	// readable value
	Error string
	Value interface{}
}

func (*SelectField) Bind

func (t *SelectField) Bind(c *web.Context, texts *Text)

func (*SelectField) GetRenderDetails

func (t *SelectField) GetRenderDetails() (name, desc, caption, err string)

func (*SelectField) HTML

func (t *SelectField) HTML() template.HTML

func (*SelectField) Render

func (t *SelectField) Render(buffer *bytes.Buffer)

func (*SelectField) RowHTML

func (t *SelectField) RowHTML() template.HTML

func (*SelectField) SetAttribute

func (t *SelectField) SetAttribute(key, value string)

type Text

type Text struct {
	ErrorRequired       string
	ErrorTooLong        string
	ErrorTooShort       string
	ErrorInvalidEmail   string
	ErrorInvalidWebsite string
	ErrorInvalidDate    string
	ErrorValueBelowMin  string
	ErrorValueAboveMax  string
}

Text is a collection of text strings used by the package

type UploadedFile

type UploadedFile struct {
	Filename    string
	ContentType string
	File        io.ReadSeeker
}

func (*UploadedFile) Bytes

func (u *UploadedFile) Bytes() []byte

type XSRFField

type XSRFField struct {
	C *web.Context

	Error string
	// contains filtered or unexported fields
}

func (*XSRFField) Bind

func (t *XSRFField) Bind(c *web.Context, texts *Text)

func (*XSRFField) GetRenderDetails

func (t *XSRFField) GetRenderDetails() (name, desc, caption, err string)

func (*XSRFField) HTML

func (t *XSRFField) HTML() template.HTML

func (*XSRFField) Render

func (t *XSRFField) Render(buffer *bytes.Buffer)

func (*XSRFField) RowHTML

func (t *XSRFField) RowHTML() template.HTML

func (*XSRFField) SetAttribute

func (t *XSRFField) SetAttribute(name, value string)

Jump to

Keyboard shortcuts

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