fields

package
v1.6.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ErrRegexInvalid = errs.Error("regex does not match")
)

Variables

This section is empty.

Functions

func DecFunc

func DecFunc[T Decoder](f func(io.Reader) T) func(io.Reader) Decoder

func EncFunc

func EncFunc[T Encoder](f func(io.Writer) T) func(io.Writer) Encoder

func HelpText

func HelpText(helpText any) func(Field)

func Hide

func Hide(b bool) func(Field)

func IsZero

func IsZero(value interface{}) bool

func Label

func Label(label any) func(Field)

func MaxLength

func MaxLength(max int) func(Field)

func MinLength

func MinLength(min int) func(Field)

func Name

func Name(name string) func(Field)

func ReadOnly

func ReadOnly(b bool) func(Field)

func Regex

func Regex(regex string) func(Field)

func Required

func Required(b bool) func(Field)

func Validators

func Validators(validators ...func(interface{}) error) func(Field)

func Widget

func Widget(w widgets.Widget) func(Field)

Types

type BaseField

type BaseField struct {
	FieldName    string
	Required_    bool
	ReadOnly_    bool
	Attributes   map[string]string
	Validators   []func(interface{}) error
	FormLabel    func() string
	FormHelpText func() string
	FormWidget   widgets.Widget
	Caser        *cases.Caser
}

func NewField

func NewField(opts ...func(Field)) *BaseField

func (*BaseField) Attrs

func (i *BaseField) Attrs() map[string]string

func (*BaseField) Clean

func (i *BaseField) Clean(value interface{}) (interface{}, error)

func (*BaseField) HasChanged

func (i *BaseField) HasChanged(initial, data interface{}) bool

func (*BaseField) HelpText

func (i *BaseField) HelpText() string

func (*BaseField) Hide

func (i *BaseField) Hide(hidden bool)

func (*BaseField) IsEmpty

func (i *BaseField) IsEmpty(value interface{}) bool

func (*BaseField) Label

func (i *BaseField) Label() string

func (*BaseField) Name

func (i *BaseField) Name() string

func (*BaseField) ReadOnly

func (i *BaseField) ReadOnly() bool

func (*BaseField) Required

func (i *BaseField) Required() bool

func (*BaseField) SetAttrs

func (i *BaseField) SetAttrs(attrs map[string]string)

func (*BaseField) SetHelpText

func (i *BaseField) SetHelpText(helpText func() string)

func (*BaseField) SetLabel

func (i *BaseField) SetLabel(label func() string)

func (*BaseField) SetName

func (i *BaseField) SetName(name string)

func (*BaseField) SetReadOnly

func (i *BaseField) SetReadOnly(b bool)

func (*BaseField) SetRequired

func (i *BaseField) SetRequired(b bool)

func (*BaseField) SetValidators

func (i *BaseField) SetValidators(validators ...func(interface{}) error)

func (*BaseField) SetWidget

func (i *BaseField) SetWidget(w widgets.Widget)

func (*BaseField) Validate

func (i *BaseField) Validate(value interface{}) []error

func (*BaseField) ValueToForm

func (i *BaseField) ValueToForm(value interface{}) interface{}

func (*BaseField) ValueToGo

func (i *BaseField) ValueToGo(value interface{}) (interface{}, error)

func (*BaseField) Widget

func (i *BaseField) Widget() widgets.Widget

type Decoder

type Decoder interface {
	Decode(interface{}) error
}

type EmailFormField

type EmailFormField struct {
	*BaseField
}

func (*EmailFormField) ValueToForm

func (e *EmailFormField) ValueToForm(value interface{}) interface{}

func (*EmailFormField) ValueToGo

func (e *EmailFormField) ValueToGo(value interface{}) (interface{}, error)

type Encoder

type Encoder interface {
	Encode(interface{}) error
}

type Field

type Field interface {
	Attrs() map[string]string
	SetAttrs(attrs map[string]string)
	Hide(hidden bool)

	SetName(name string)
	SetLabel(label func() string)
	SetHelpText(helpText func() string)
	SetValidators(validators ...func(interface{}) error)
	SetWidget(widget widgets.Widget)

	Name() string
	Label() string
	HelpText() string
	Validate(value interface{}) []error
	Widget() widgets.Widget
	HasChanged(initial, data interface{}) bool

	Clean(value interface{}) (interface{}, error)
	ValueToForm(value interface{}) interface{}
	ValueToGo(value interface{}) (interface{}, error)
	Required() bool
	SetRequired(b bool)
	ReadOnly() bool
	SetReadOnly(b bool)
	IsEmpty(value interface{}) bool
}

func BooleanField

func BooleanField(opts ...func(Field)) Field

func CharField

func CharField(opts ...func(Field)) Field

func DateField

func DateField(typ widgets.DateWidgetType, opts ...func(Field)) Field

func DecimalField added in v1.6.7

func DecimalField(opts ...func(Field)) Field

func EmailField

func EmailField(opts ...func(Field)) Field

func NumberField

func NumberField[T widgets.NumberType](opts ...func(Field)) Field

type FileStorageField added in v1.6.8

type FileStorageField struct {
	*BaseField
	StorageEngine string
	UploadTo      func(fileObject *widgets.FileObject) string
	Validators    []func(filename string, file io.Reader) error
}

func FileField added in v1.6.8

func FileField(engine string, opts ...func(Field)) *FileStorageField

func (*FileStorageField) Save added in v1.6.8

func (f *FileStorageField) Save(value interface{}) (interface{}, error)

func (*FileStorageField) Widget added in v1.6.8

func (f *FileStorageField) Widget() widgets.Widget

type JSONFormField

type JSONFormField[T any] struct {
	*MarshallerFormField[T]
}

A wrapper around MarshallerFormField to better handle returned errors by ValueToGo

func JSONField

func JSONField[T any](opts ...func(Field)) *JSONFormField[T]

func (*JSONFormField[T]) ValueToGo

func (j *JSONFormField[T]) ValueToGo(value interface{}) (interface{}, error)

type MarshallerFormField

type MarshallerFormField[T any] struct {
	*BaseField
	NewEncoder func(b io.Writer) Encoder
	NewDecoder func(b io.Reader) Decoder
}

func MarshallerField

func MarshallerField[T any](encoder func(io.Writer) Encoder, decoder func(io.Reader) Decoder, opts ...func(Field)) *MarshallerFormField[T]

func (*MarshallerFormField[T]) ValueToForm

func (m *MarshallerFormField[T]) ValueToForm(value interface{}) interface{}

func (*MarshallerFormField[T]) ValueToGo

func (m *MarshallerFormField[T]) ValueToGo(value interface{}) (interface{}, error)

type NullableSQLField added in v1.6.7

type NullableSQLField[SQLType any] struct {
	*BaseField
}

func SQLNullField added in v1.6.7

func SQLNullField[SQLType any](opts ...func(Field)) *NullableSQLField[SQLType]

func (*NullableSQLField[SQLType]) ValueToForm added in v1.6.7

func (n *NullableSQLField[SQLType]) ValueToForm(value interface{}) interface{}

func (*NullableSQLField[SQLType]) ValueToGo added in v1.6.7

func (n *NullableSQLField[SQLType]) ValueToGo(value interface{}) (interface{}, error)

func (*NullableSQLField[SQLType]) Widget added in v1.6.7

func (n *NullableSQLField[SQLType]) Widget() widgets.Widget

type ProtectedFormField

type ProtectedFormField struct {
	Field
	ErrorMessage func(err error) error
}

Translates errors which might have too much information into a generic error message.

func Protect

func Protect(w Field, errFn func(err error) error) *ProtectedFormField

func (*ProtectedFormField) Clean

func (pw *ProtectedFormField) Clean(value interface{}) (interface{}, error)

func (*ProtectedFormField) Validate

func (pw *ProtectedFormField) Validate(value interface{}) []error

func (*ProtectedFormField) ValueToGo

func (pw *ProtectedFormField) ValueToGo(value interface{}) (interface{}, error)

type SaveableField added in v1.6.8

type SaveableField interface {
	Field
	Save(value interface{}) (interface{}, error)
}

Jump to

Keyboard shortcuts

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