forms

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: GPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitTemplateLibrary added in v1.6.6

func InitTemplateLibrary()

func Initialize

func Initialize[T Form](f T, initfuncs ...func(Form)) T

func OnFinalize

func OnFinalize(funcs ...func(Form)) func(Form)

func OnInvalid

func OnInvalid(funcs ...func(Form)) func(Form)

func OnValid

func OnValid(funcs ...func(Form)) func(Form)

func WithData

func WithData(data url.Values, files map[string][]filesystem.FileHeader, r *http.Request) func(Form)

func WithFields

func WithFields(fields ...fields.Field) func(Form)

func WithInitial

func WithInitial(initial map[string]interface{}) func(Form)

func WithPrefix

func WithPrefix(prefix string) func(Form)

func WithRequestData

func WithRequestData(method string, r *http.Request) func(Form)

Types

type BaseForm

type BaseForm struct {
	FormPrefix string

	FormFields      *orderedmap.OrderedMap[string, fields.Field]
	FormWidgets     *orderedmap.OrderedMap[string, widgets.Widget]
	Errors          *orderedmap.OrderedMap[string, []error]
	ErrorList_      []error
	Raw             url.Values
	Initial         map[string]interface{}
	InvalidDefaults map[string]interface{}
	Files           map[string][]filesystem.FileHeader
	Cleaned         map[string]interface{}
	Defaults        map[string]interface{}

	Validators      []func(Form) []error
	OnValidFuncs    []func(Form)
	OnInvalidFuncs  []func(Form)
	OnFinalizeFuncs []func(Form)
	// contains filtered or unexported fields
}

func NewBaseForm

func NewBaseForm(opts ...func(Form)) *BaseForm

func (*BaseForm) AddError

func (f *BaseForm) AddError(name string, errorList ...error)

func (*BaseForm) AddField

func (f *BaseForm) AddField(name string, field fields.Field)

func (*BaseForm) AddFormError

func (f *BaseForm) AddFormError(errorList ...error)

func (*BaseForm) AddWidget

func (f *BaseForm) AddWidget(name string, widget widgets.Widget)

func (*BaseForm) AsP

func (f *BaseForm) AsP() template.HTML

func (*BaseForm) AsUL

func (f *BaseForm) AsUL() template.HTML

func (*BaseForm) BoundErrors

func (f *BaseForm) BoundErrors() *orderedmap.OrderedMap[string, []error]

func (*BaseForm) BoundFields

func (f *BaseForm) BoundFields() *orderedmap.OrderedMap[string, BoundField]

func (*BaseForm) BoundForm

func (f *BaseForm) BoundForm() BoundForm

func (*BaseForm) CleanedData

func (f *BaseForm) CleanedData() map[string]interface{}

func (*BaseForm) DeleteField

func (f *BaseForm) DeleteField(name string) bool

func (*BaseForm) EditContext

func (f *BaseForm) EditContext(key string, context ctx.Context)

func (*BaseForm) ErrorList

func (f *BaseForm) ErrorList() []error

func (*BaseForm) Field

func (f *BaseForm) Field(name string) (fields.Field, bool)

func (*BaseForm) FieldOrder

func (f *BaseForm) FieldOrder() []string

func (*BaseForm) Fields

func (f *BaseForm) Fields() []fields.Field

func (*BaseForm) FormValue

func (f *BaseForm) FormValue(name string) interface{}

func (*BaseForm) FullClean

func (f *BaseForm) FullClean()

func (*BaseForm) HasChanged

func (f *BaseForm) HasChanged() bool

func (*BaseForm) InitialData

func (f *BaseForm) InitialData() map[string]interface{}

func (*BaseForm) IsValid

func (f *BaseForm) IsValid() bool

func (*BaseForm) Media

func (f *BaseForm) Media() media.Media

func (*BaseForm) OnFinalize

func (f *BaseForm) OnFinalize(funcs ...func(Form))

func (*BaseForm) OnInvalid

func (f *BaseForm) OnInvalid(funcs ...func(Form))

func (*BaseForm) OnValid

func (f *BaseForm) OnValid(funcs ...func(Form))

func (*BaseForm) Ordering

func (f *BaseForm) Ordering(order []string)

func (*BaseForm) Prefix

func (f *BaseForm) Prefix() string

func (*BaseForm) Reset

func (f *BaseForm) Reset()

func (*BaseForm) SetInitial

func (f *BaseForm) SetInitial(initial map[string]interface{})

func (*BaseForm) SetPrefix

func (f *BaseForm) SetPrefix(prefix string)

func (*BaseForm) SetValidators

func (f *BaseForm) SetValidators(validators ...func(Form) []error)

func (*BaseForm) Validate

func (f *BaseForm) Validate()

func (*BaseForm) Widget

func (f *BaseForm) Widget(name string) (widgets.Widget, bool)

func (*BaseForm) Widgets

func (f *BaseForm) Widgets() []widgets.Widget

func (*BaseForm) WithData

func (f *BaseForm) WithData(data url.Values, files map[string][]filesystem.FileHeader, r *http.Request) Form

type BaseFormset

type BaseFormset struct {
	MainForm Form
	MinNum   int
	MaxNum   int
}

type BoundField

type BoundField interface {
	ID() string
	Name() string
	Widget() widgets.Widget
	Input() fields.Field
	Label() template.HTML
	HelpText() template.HTML
	Field() template.HTML
	HTML() template.HTML
	Attrs() map[string]string
	Value() interface{}
	Errors() []error
}

func NewBoundFormField

func NewBoundFormField(w widgets.Widget, f fields.Field, name string, value interface{}, errors []error) BoundField

type BoundForm

type BoundForm interface {
	AsP() template.HTML
	AsUL() template.HTML
	Media() media.Media
	Fields() []BoundField
	ErrorList() []error
	UnpackErrors() []FieldError
	Errors() *orderedmap.OrderedMap[string, []error]
}

type BoundFormField

type BoundFormField struct {
	FormWidget widgets.Widget
	FormField  fields.Field
	FormName   string
	FormAttrs  map[string]string
	FormValue  interface{}
	FormErrors []error
	CachedHTML template.HTML
}

func (*BoundFormField) Attrs

func (b *BoundFormField) Attrs() map[string]string

func (*BoundFormField) Errors

func (b *BoundFormField) Errors() []error

func (*BoundFormField) Field

func (b *BoundFormField) Field() template.HTML

func (*BoundFormField) HTML

func (b *BoundFormField) HTML() template.HTML

func (*BoundFormField) HelpText

func (b *BoundFormField) HelpText() template.HTML

func (*BoundFormField) ID

func (b *BoundFormField) ID() string

func (*BoundFormField) Input

func (b *BoundFormField) Input() fields.Field

func (*BoundFormField) Label

func (b *BoundFormField) Label() template.HTML

func (*BoundFormField) Name

func (b *BoundFormField) Name() string

func (*BoundFormField) Value

func (b *BoundFormField) Value() interface{}

func (*BoundFormField) Widget

func (b *BoundFormField) Widget() widgets.Widget

type Cleaner

type Cleaner interface {
	Clean(value interface{}) (interface{}, error)
}

type ErrorAdder

type ErrorAdder interface {
	AddFormError(errorList ...error)
	AddError(name string, errorList ...error)
}

type FieldError

type FieldError interface {
	Field() string
	Errors() []error
}

type Form

type Form interface {
	FormRenderer

	Prefix() string
	SetPrefix(prefix string)
	SetInitial(initial map[string]interface{})
	SetValidators(validators ...func(Form) []error)
	Ordering([]string)
	FieldOrder() []string

	Field(name string) (fields.Field, bool)
	Widget(name string) (widgets.Widget, bool)
	Fields() []fields.Field
	Widgets() []widgets.Widget
	AddField(name string, field fields.Field)
	AddWidget(name string, widget widgets.Widget)
	DeleteField(name string) bool
	BoundForm() BoundForm
	BoundFields() *orderedmap.OrderedMap[string, BoundField]
	BoundErrors() *orderedmap.OrderedMap[string, []error]
	ErrorList() []error

	WithData(data url.Values, files map[string][]filesystem.FileHeader, r *http.Request) Form
	InitialData() map[string]interface{}
	CleanedData() map[string]interface{}

	FullClean()
	Validate()
	HasChanged() bool
	IsValid() bool

	OnValid(...func(Form))
	OnInvalid(...func(Form))
	OnFinalize(...func(Form))
}

type FormRenderer

type FormRenderer interface {
	AsP() template.HTML
	AsUL() template.HTML
	Media() media.Media
}

type Validator

type Validator interface {
	Validate(value interface{}) []error
}

Directories

Path Synopsis
templ: version: v0.2.707
templ: version: v0.2.707

Jump to

Keyboard shortcuts

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