Documentation
¶
Index ¶
- func FormValueFromDataDict[T any](ctx context.Context, form FormFieldDefiner, name string, data url.Values, ...) (T, bool, []error)
- func FullClean(ctx context.Context, f Form) (invalid, defaults, cleaned map[string]any)
- func IsValid[T any](ctx context.Context, formObj T) bool
- type BinderWidget
- type BoundField
- type BoundForm
- type CleanableForm
- type Cleaner
- type ErrorAdder
- type ErrorDefiner
- type Field
- type FieldError
- type Form
- type FormFieldDefiner
- type FormRenderer
- type FormValueConverter
- type FormValueGetter
- type FormValueOmitter
- type FormValuer
- type FormWrapper
- type FullCleanMixin
- type IsValidChecker
- type IsValidDefiner
- type Option
- type PrevalidatorMixin
- type SaveableField
- type Validator
- type ValidatorMixin
- type Widget
- type WithDataDefiner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormValueFromDataDict ¶
func FormValueFromDataDict[T any](ctx context.Context, form FormFieldDefiner, name string, data url.Values, files map[string][]filesystem.FileHeader) (T, bool, []error)
Types ¶
type BinderWidget ¶
type BoundField ¶
type BoundForm ¶
type BoundForm interface {
AsP() template.HTML
AsUL() template.HTML
AsTable() template.HTML
Media() media.Media
Fields() []BoundField
FieldMap() map[string]BoundField // map of field name to BoundField
ErrorList() []error
UnpackErrors() []FieldError
Errors() *orderedmap.OrderedMap[string, []error]
}
type CleanableForm ¶
type ErrorAdder ¶
type ErrorDefiner ¶
type ErrorDefiner interface {
ErrorList() []error
BoundErrors() *orderedmap.OrderedMap[string, []error]
}
type Field ¶
type Field interface {
FormValueConverter
Attrs() map[string]string
SetAttrs(attrs map[string]string)
Hide(hidden bool)
SetName(name string)
SetLabel(label func(ctx context.Context) string)
SetHelpText(helpText func(ctx context.Context) string)
SetValidators(validators ...func(interface{}) error)
SetDefault(defaultValue func() interface{})
SetWidget(widget Widget)
Name() string
Label(ctx context.Context) string
HelpText(ctx context.Context) string
Validate(ctx context.Context, value interface{}) []error
Widget() Widget
Default() interface{}
HasChanged(initial, data interface{}) bool
Clean(ctx context.Context, value interface{}) (interface{}, error)
Required() bool
SetRequired(b bool)
ReadOnly() bool
SetReadOnly(b bool)
IsEmpty(value interface{}) bool
}
type FieldError ¶
type Form ¶
type Form interface {
WithDataDefiner
FullCleanMixin
ErrorAdder
ErrorDefiner
Media() media.Media
Context() context.Context
WithContext(ctx context.Context)
Prefix() string
SetPrefix(prefix string)
SetInitial(initial map[string]interface{})
Validators() []func(f Form, cleanedData map[string]interface{}) []error
SetValidators(validators ...func(Form, map[string]interface{}) []error)
Renderer() FormRenderer
SetRenderer(renderer FormRenderer)
Ordering([]string)
FieldOrder() []string
Field(name string) (Field, bool)
Fields() []Field
Widgets() []Widget
AddField(name string, field Field)
AddWidget(name string, widget Widget)
DeleteField(name string) bool
BoundForm() BoundForm
BoundFields() *orderedmap.OrderedMap[string, BoundField]
InitialData() map[string]interface{}
CleanedData() map[string]interface{}
OnValid(...func(Form))
OnInvalid(...func(Form))
OnFinalize(...func(Form))
WasCleaned() bool
HasChanged() bool
CallbackOnValid() []func(f Form)
CallbackOnInvalid() []func(f Form)
CallbackOnFinalize() []func(f Form)
CleanedDataUnsafe() map[string]interface{}
}
type FormFieldDefiner ¶
type FormRenderer ¶
type FormRenderer interface {
RenderAsP(w io.Writer, ctx context.Context, form BoundForm) error
RenderAsUL(w io.Writer, ctx context.Context, form BoundForm) error
RenderAsTable(w io.Writer, ctx context.Context, form BoundForm) error
RenderFieldLabel(w io.Writer, ctx context.Context, field BoundField, id string, name string) error
RenderFieldHelpText(w io.Writer, ctx context.Context, field BoundField, id string, name string) error
RenderFieldWidget(w io.Writer, ctx context.Context, field BoundField, id string, name string, value interface{}, attrs map[string]string, errors []error, widgetCtx ctx.Context) error
RenderField(w io.Writer, ctx context.Context, field BoundField, id string, name string, value interface{}, errors []error, attrs map[string]string, widgetCtx ctx.Context) error
}
type FormValueConverter ¶
type FormValueConverter interface {
// Convert the forms' string value to the appropriate GO type.
ValueToGo(value interface{}) (interface{}, error)
// Convert the GO type to the forms' string value.
ValueToForm(value interface{}) interface{}
}
type FormValueGetter ¶
type FormValueGetter interface {
// Get the value from the provided data.
ValueFromDataDict(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)
}
type FormValueOmitter ¶
type FormValueOmitter interface {
// Check if the value is omitted from the data provided.
ValueOmittedFromData(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) bool
}
type FormValuer ¶
type FormValuer interface {
FormValueConverter
FormValueOmitter
FormValueGetter
}
type FormWrapper ¶
type FormWrapper[T any] interface { Unwrap() []T }
type FullCleanMixin ¶
type FullCleanMixin interface {
Widget(name string) (Widget, bool)
PrefixName(fieldName string) string
FieldMap() *orderedmap.OrderedMap[string, Field]
// BindCleanedData might be called multiple times for a single IsValid() call
BindCleanedData(invalid, defaults, cleaned map[string]interface{})
}
type IsValidChecker ¶
type IsValidDefiner ¶
type IsValidDefiner interface {
IsValid() bool
}
type PrevalidatorMixin ¶
type PrevalidatorMixin interface {
Prevalidate(ctx context.Context, root any, data url.Values, files map[string][]filesystem.FileHeader) []error
}
type SaveableField ¶
type ValidatorMixin ¶
type Widget ¶
type Widget interface {
IsHidden() bool
Hide(hidden bool)
FormType() string
Field() Field
BindField(field Field)
SetAttrs(attrs map[string]string)
IdForLabel(id string) string
GetContextData(ctx context.Context, id, name string, value interface{}, attrs map[string]string) ctx.Context
RenderWithErrors(ctx context.Context, w io.Writer, id, name string, value interface{}, errors []error, attrs map[string]string, context ctx.Context) error
// Render is basically the same as RenderWithErrors, except that it does not take a context.
// The widget should always be able to generate some sort of context itself based on the provided parameters.
Render(ctx context.Context, w io.Writer, id, name string, value interface{}, attrs map[string]string) error
Validate(ctx context.Context, value interface{}) []error
FormValuer
media.MediaDefiner
}
type WithDataDefiner ¶
type WithDataDefiner interface {
WithData(data url.Values, files map[string][]filesystem.FileHeader, r *http.Request)
Data() (url.Values, map[string][]filesystem.FileHeader)
}
Click to show internal directories.
Click to hide internal directories.