Documentation
¶
Index ¶
- Variables
- type Attrs
- type BoundField
- type BoundFieldGroup
- type BoundForm
- type Choice
- type ErrorDict
- type ErrorList
- type Field
- func BooleanField(options FieldOptions) *Field
- func CharField(options FieldOptions) *Field
- func ChoiceField(options FieldOptions, choices []Choice) *Field
- func ComboField(options FieldOptions, fields ...*Field) *Field
- func DateField(options FieldOptions) *Field
- func DateTimeField(options FieldOptions) *Field
- func DecimalField(options FieldOptions) *Field
- func DurationField(options FieldOptions) *Field
- func EmailField(options FieldOptions) *Field
- func FileField(options FieldOptions) *Field
- func FloatField(options FieldOptions) *Field
- func GenericIPAddressField(options FieldOptions) *Field
- func ImageField(options FieldOptions) *Field
- func IntegerField(options FieldOptions) *Field
- func JSONField(options FieldOptions) *Field
- func ModelChoiceField(options FieldOptions, choices []Choice) *Field
- func ModelMultipleChoiceField(options FieldOptions, choices []Choice) *Field
- func MultiValueField(options FieldOptions, fields ...*Field) *Field
- func MultipleChoiceField(options FieldOptions, choices []Choice) *Field
- func MultipleFileField(options FieldOptions) *Field
- func RegexField(options FieldOptions, pattern *regexp.Regexp) *Field
- func SlugField(options FieldOptions) *Field
- func SplitDateTimeField(options FieldOptions) *Field
- func TimeField(options FieldOptions) *Field
- func TypedChoiceField(options FieldOptions, choices []Choice, coerce func(string) (any, error)) *Field
- func URLField(options FieldOptions) *Field
- func UUIDField(options FieldOptions) *Field
- type FieldGroup
- type FieldOptions
- type Form
- func (f *Form) AddError(field string, err error)
- func (f *Form) AddNonFieldError(err error)
- func (f *Form) BoundField(name string) BoundField
- func (f *Form) ChangedData() []string
- func (f *Form) Errors() ErrorDict
- func (f *Form) FieldErrors(name string) ErrorList
- func (f *Form) FieldGroups() []BoundFieldGroup
- func (f *Form) FieldNames() []string
- func (f *Form) FullClean()
- func (f *Form) HiddenFields() []BoundField
- func (f *Form) IsBound() bool
- func (f *Form) IsValid() bool
- func (f *Form) Media() Media
- func (f *Form) NonFieldErrors() NonFieldErrorList
- func (f *Form) Render() string
- func (f *Form) RenderErrors() string
- func (f *Form) VisibleFields() []BoundField
- type FormCleanFunc
- type FormOptions
- type FormSet
- func (fs *FormSet) DeletedForms() []BoundForm
- func (fs *FormSet) EmptyForms() []BoundForm
- func (fs *FormSet) Forms() []BoundForm
- func (fs *FormSet) InitialForms() []BoundForm
- func (fs *FormSet) IsValid() bool
- func (fs *FormSet) ManagementForm() ManagementForm
- func (fs *FormSet) NewForms() []BoundForm
- func (fs *FormSet) NonFormErrors() ErrorList
- func (fs *FormSet) OrderedForms() []BoundForm
- type FormSetFormFactory
- type FormSetFormOptions
- type FormSetOptions
- type InlineFormSet
- type InlineFormSetOptions
- type ManagementForm
- type Media
- type MediaProvider
- type ModelFieldFactory
- type ModelForm
- type ModelFormOptions
- type NonFieldErrorList
- type UploadedFile
- type ValidationError
- type Validator
- type Widget
- func CheckboxInput() Widget
- func CheckboxSelectMultiple(choices []Choice) Widget
- func ClearableFileInput() Widget
- func DateInput() Widget
- func DateTimeInput() Widget
- func EmailInput() Widget
- func FileInput() Widget
- func HiddenInput() Widget
- func MultipleHiddenInput() Widget
- func NumberInput() Widget
- func PasswordInput() Widget
- func RadioSelect(choices []Choice) Widget
- func Select(choices []Choice) Widget
- func SelectMultiple(choices []Choice) Widget
- func SplitDateTimeWidget() Widget
- func TextInput() Widget
- func Textarea() Widget
- func TimeInput() Widget
- func URLInput() Widget
Constants ¶
This section is empty.
Variables ¶
var ErrValidation = errors.New("form validation")
ErrValidation indicates form field validation failed.
Functions ¶
This section is empty.
Types ¶
type BoundField ¶
BoundField is one field bound to a form instance.
func (BoundField) Errors ¶
func (bf BoundField) Errors() ErrorList
func (BoundField) HTMLName ¶
func (bf BoundField) HTMLName() string
func (BoundField) IsHidden ¶
func (bf BoundField) IsHidden() bool
func (BoundField) Label ¶
func (bf BoundField) Label() string
func (BoundField) LabelTag ¶
func (bf BoundField) LabelTag() string
func (BoundField) Render ¶
func (bf BoundField) Render() string
func (BoundField) Value ¶
func (bf BoundField) Value() any
type BoundFieldGroup ¶
type BoundFieldGroup struct {
Name string
Fields []BoundField
}
BoundFieldGroup is a field group resolved to bound fields.
type ErrorList ¶
type ErrorList []ValidationError
ErrorList is an ordered list of validation errors.
type Field ¶
type Field struct {
Kind string
Options FieldOptions
Choices []Choice
Fields []*Field
Regex *regexp.Regexp
Coerce func(string) (any, error)
CleanFunc func(any) (any, error)
Compress func([]any) (any, error)
EmptyValue any
}
Field parses and validates one form value.
func BooleanField ¶
func BooleanField(options FieldOptions) *Field
func CharField ¶
func CharField(options FieldOptions) *Field
func ChoiceField ¶
func ChoiceField(options FieldOptions, choices []Choice) *Field
func ComboField ¶
func ComboField(options FieldOptions, fields ...*Field) *Field
func DateField ¶
func DateField(options FieldOptions) *Field
func DateTimeField ¶
func DateTimeField(options FieldOptions) *Field
func DecimalField ¶
func DecimalField(options FieldOptions) *Field
func DurationField ¶
func DurationField(options FieldOptions) *Field
func EmailField ¶
func EmailField(options FieldOptions) *Field
func FileField ¶
func FileField(options FieldOptions) *Field
func FloatField ¶
func FloatField(options FieldOptions) *Field
func GenericIPAddressField ¶
func GenericIPAddressField(options FieldOptions) *Field
func ImageField ¶
func ImageField(options FieldOptions) *Field
func IntegerField ¶
func IntegerField(options FieldOptions) *Field
func JSONField ¶
func JSONField(options FieldOptions) *Field
func ModelChoiceField ¶
func ModelChoiceField(options FieldOptions, choices []Choice) *Field
func ModelMultipleChoiceField ¶
func ModelMultipleChoiceField(options FieldOptions, choices []Choice) *Field
func MultiValueField ¶
func MultiValueField(options FieldOptions, fields ...*Field) *Field
func MultipleChoiceField ¶
func MultipleChoiceField(options FieldOptions, choices []Choice) *Field
func MultipleFileField ¶
func MultipleFileField(options FieldOptions) *Field
func RegexField ¶
func RegexField(options FieldOptions, pattern *regexp.Regexp) *Field
func SlugField ¶
func SlugField(options FieldOptions) *Field
func SplitDateTimeField ¶
func SplitDateTimeField(options FieldOptions) *Field
func TimeField ¶
func TimeField(options FieldOptions) *Field
func TypedChoiceField ¶
func URLField ¶
func URLField(options FieldOptions) *Field
func UUIDField ¶
func UUIDField(options FieldOptions) *Field
type FieldGroup ¶
FieldGroup defines a named group of form fields.
type FieldOptions ¶
type FieldOptions struct {
Required bool
Label string
Initial any
HelpText string
Validators []Validator
Disabled bool
Localize bool
ErrorMessages map[string]string
Widget any
}
FieldOptions configures common form field behavior.
type Form ¶
Form binds data to fields and coordinates validation and rendering.
func NewForm ¶
func NewForm(options FormOptions) *Form
func (*Form) AddNonFieldError ¶
func (*Form) BoundField ¶
func (f *Form) BoundField(name string) BoundField
func (*Form) ChangedData ¶
func (*Form) FieldErrors ¶
func (*Form) FieldGroups ¶
func (f *Form) FieldGroups() []BoundFieldGroup
func (*Form) FieldNames ¶
func (*Form) HiddenFields ¶
func (f *Form) HiddenFields() []BoundField
func (*Form) NonFieldErrors ¶
func (f *Form) NonFieldErrors() NonFieldErrorList
func (*Form) RenderErrors ¶
func (*Form) VisibleFields ¶
func (f *Form) VisibleFields() []BoundField
type FormCleanFunc ¶
FormCleanFunc validates cross-field state after individual fields clean.
type FormOptions ¶
type FormOptions struct {
Fields map[string]*Field
FieldOrder []string
Data map[string]any
Initial map[string]any
Prefix string
Bound bool
Groups []FieldGroup
Clean FormCleanFunc
}
FormOptions configures a form instance.
type FormSet ¶
type FormSet struct {
// contains filtered or unexported fields
}
FormSet coordinates repeated instances of one form.
func NewFormSet ¶
func NewFormSet(options FormSetOptions) *FormSet
func (*FormSet) DeletedForms ¶
func (*FormSet) EmptyForms ¶
func (*FormSet) InitialForms ¶
func (*FormSet) ManagementForm ¶
func (fs *FormSet) ManagementForm() ManagementForm
func (*FormSet) NonFormErrors ¶
func (*FormSet) OrderedForms ¶
type FormSetFormFactory ¶
type FormSetFormFactory func(FormSetFormOptions) *Form
FormSetFormFactory builds one form for an index.
type FormSetFormOptions ¶
type FormSetFormOptions struct {
Index int
Prefix string
Data map[string]any
Initial map[string]any
}
FormSetFormOptions configures one form inside a formset.
type FormSetOptions ¶
type FormSetOptions struct {
Prefix string
Data map[string]any
Initial []map[string]any
Extra int
MinForms int
MaxForms int
CanDelete bool
CanOrder bool
FormFactory FormSetFormFactory
}
FormSetOptions configures a Django-style formset.
type InlineFormSet ¶
type InlineFormSet struct {
*FormSet
Parent models.Model
RelationField string
ModelForms []*ModelForm
Store models.InstanceStore
Context context.Context
SaveOptions []models.SaveOption
}
InlineFormSet stores a formset of child model forms.
func NewInlineFormSet ¶
func NewInlineFormSet(options InlineFormSetOptions) *InlineFormSet
type InlineFormSetOptions ¶
type InlineFormSetOptions struct {
FormSetOptions
Parent models.Model
RelationField string
ModelFactory func(index int) models.Model
ModelFields []modelfields.Field
Include []string
Exclude []string
Labels map[string]string
HelpTexts map[string]string
Widgets map[string]Widget
FieldClasses map[string]ModelFieldFactory
Store models.InstanceStore
Context context.Context
SaveOptions []models.SaveOption
}
InlineFormSetOptions configures model forms tied to one parent model.
type ManagementForm ¶
ManagementForm stores parsed formset management counters.
type MediaProvider ¶
type MediaProvider interface {
Media() Media
}
MediaProvider is implemented by widgets that need CSS or JavaScript assets.
type ModelFieldFactory ¶
type ModelFieldFactory func(modelfields.Field, FieldOptions) *Field
ModelFieldFactory overrides the generated form field for one model field.
type ModelForm ¶
type ModelForm struct {
*Form
Model models.Model
Meta models.Metadata
Store models.InstanceStore
Context context.Context
SaveOptions []models.SaveOption
// contains filtered or unexported fields
}
ModelForm binds a Form to a model instance.
func NewModelForm ¶
func NewModelForm(options ModelFormOptions) *ModelForm
type ModelFormOptions ¶
type ModelFormOptions struct {
Model models.Model
Meta models.Metadata
ModelFields []modelfields.Field
Include []string
Exclude []string
Labels map[string]string
HelpTexts map[string]string
Widgets map[string]Widget
FieldClasses map[string]ModelFieldFactory
LocalizedFields []string
ReadOnly []string
Data map[string]any
Initial map[string]any
Prefix string
Groups []FieldGroup
Clean FormCleanFunc
Store models.InstanceStore
Context context.Context
SaveOptions []models.SaveOption
}
ModelFormOptions configures a model-backed form.
type NonFieldErrorList ¶
type NonFieldErrorList ErrorList
NonFieldErrorList renders form-level errors with a distinct CSS class.
func (NonFieldErrorList) HTML ¶
func (l NonFieldErrorList) HTML() string
func (NonFieldErrorList) Messages ¶
func (l NonFieldErrorList) Messages() []string
type UploadedFile ¶
UploadedFile is a form-level uploaded file value.
type ValidationError ¶
ValidationError is a user-facing form validation error.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
type Widget ¶
Widget renders one form value into HTML.
func CheckboxInput ¶
func CheckboxInput() Widget
func CheckboxSelectMultiple ¶
func ClearableFileInput ¶
func ClearableFileInput() Widget
func DateTimeInput ¶
func DateTimeInput() Widget
func EmailInput ¶
func EmailInput() Widget
func HiddenInput ¶
func HiddenInput() Widget
func MultipleHiddenInput ¶
func MultipleHiddenInput() Widget
func NumberInput ¶
func NumberInput() Widget
func PasswordInput ¶
func PasswordInput() Widget
func RadioSelect ¶
func SelectMultiple ¶
func SplitDateTimeWidget ¶
func SplitDateTimeWidget() Widget