fields

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 24 Imported by: 7

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func Attributes added in v1.7.2

func Attributes(attrs map[string]string) func(Field)

func DecFunc

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

func Default added in v1.7.2

func Default(value interface{}) func(Field)

func EncFunc

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

func FileFieldWithExtensions added in v1.7.2

func FileFieldWithExtensions(allowedExtensions []string) func(Field)

func HelpText

func HelpText(helpText any) func(Field)

func Hide

func Hide(b bool) func(Field)

func IsZero

func IsZero(value interface{}) bool

For compatibility purposes this function stays defined here. IsZero checks if the value is zero or not.

func Label

func Label(label any) func(Field)

func MaxLength

func MaxLength(max int) func(Field)

func MaxValue added in v1.7.0

func MaxValue(max int) func(Field)

func MinLength

func MinLength(min int) func(Field)

func MinValue added in v1.7.0

func MinValue(min int) func(Field)

func Name

func Name(name string) func(Field)

func Placeholder added in v1.7.2

func Placeholder(placeholder 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(ctx context.Context) string
	FormHelpText func(ctx context.Context) string
	FormWidget   widgets.Widget
	GetDefault   func() interface{}
	Caser        *cases.Caser
	IsEmptyFunc  func(value interface{}) bool
}

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(ctx context.Context, value interface{}) (interface{}, error)

func (*BaseField) Default added in v1.7.2

func (i *BaseField) Default() interface{}

func (*BaseField) HasChanged

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

func (*BaseField) HelpText

func (i *BaseField) HelpText(ctx context.Context) 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(ctx context.Context) 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) SetDefault added in v1.7.2

func (i *BaseField) SetDefault(defaultValue func() interface{})

func (*BaseField) SetHelpText

func (i *BaseField) SetHelpText(helpText func(ctx context.Context) string)

func (*BaseField) SetLabel

func (i *BaseField) SetLabel(label func(ctx context.Context) 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(ctx context.Context, 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 = forms.Field

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
	StorageBackend mediafiles.Backend
	StorageEngine  string
	Extensions     []string // Allowed file extensions
	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) ValueToForm added in v1.7.2

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

func (*FileStorageField) ValueToGo added in v1.7.2

func (i *FileStorageField) ValueToGo(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 MultiField added in v1.7.2

type MultiField struct {
	*BaseField
	Fields []Field
}

func NewMultiField added in v1.7.2

func NewMultiField(fields []Field, opts ...func(Field)) *MultiField

func (*MultiField) Clean added in v1.7.2

func (m *MultiField) Clean(ctx context.Context, value interface{}) (interface{}, error)

func (*MultiField) HasChanged added in v1.7.2

func (m *MultiField) HasChanged(initial interface{}, data interface{}) bool

func (*MultiField) Hide added in v1.7.2

func (m *MultiField) Hide(hidden bool)

func (*MultiField) IsEmpty added in v1.7.2

func (m *MultiField) IsEmpty(value interface{}) bool

func (*MultiField) SetReadOnly added in v1.7.2

func (m *MultiField) SetReadOnly(b bool)

func (*MultiField) SetRequired added in v1.7.2

func (m *MultiField) SetRequired(b bool)

func (*MultiField) Validate added in v1.7.2

func (m *MultiField) Validate(ctx context.Context, value interface{}) []error

func (*MultiField) Widget added in v1.7.2

func (m *MultiField) Widget() widgets.Widget

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(ctx context.Context, value interface{}) (interface{}, error)

func (*ProtectedFormField) Validate

func (pw *ProtectedFormField) Validate(ctx context.Context, value interface{}) []error

func (*ProtectedFormField) ValueToGo

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

type SaveableField added in v1.6.8

type SaveableField = forms.SaveableField

Jump to

Keyboard shortcuts

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