Documentation
¶
Index ¶
- func ModelFormSetFactory(modelInstance any, includes, excludes []string, extra int) func() *BaseFormSet
- type BaseField
- type BaseFormSet
- type BaseWidget
- type BooleanField
- type CharField
- type CheckboxInput
- type CheckboxSelectMultiple
- type Choice
- type ChoiceField
- type DateField
- type EmailField
- type Field
- type FileField
- type FloatField
- type Form
- func (f *Form) Bind(data map[string]any, files map[string][]*multipart.FileHeader)
- func (f *Form) Clean() error
- func (f *Form) IsValid() bool
- func (f *Form) Media() *Media
- func (f *Form) NonFieldErrors() []string
- func (f *Form) Render() template.SafeString
- func (f *Form) RenderTable() template.SafeString
- type FormErrors
- type ImageField
- type Input
- func NewClearableFileInput(attrs map[string]string) *Input
- func NewDateInput(attrs map[string]string) *Input
- func NewDateTimeInput(attrs map[string]string) *Input
- func NewEmailInput(attrs map[string]string) *Input
- func NewFileInput(attrs map[string]string) *Input
- func NewHiddenInput(attrs map[string]string) *Input
- func NewNumberInput(attrs map[string]string) *Input
- func NewPasswordInput(attrs map[string]string) *Input
- func NewTextInput(attrs map[string]string) *Input
- func NewTimeInput(attrs map[string]string) *Input
- func NewURLInput(attrs map[string]string) *Input
- type IntegerField
- type Media
- type ModelForm
- type MultipleChoiceField
- type RadioSelect
- type Select
- type SelectMultiple
- type SlugField
- type SplitDateTimeWidget
- type Textarea
- type URLField
- type Widget
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModelFormSetFactory ¶
func ModelFormSetFactory(modelInstance any, includes, excludes []string, extra int) func() *BaseFormSet
ModelFormSetFactory generates a factory for ModelFormSets. In Django this returns a class. Here it returns a configured BaseFormSet initialization function.
Types ¶
type BaseFormSet ¶
type BaseFormSet struct {
FormFactory func() *Form // Factory to create the forms
Forms []*Form // The instantiated forms
Data map[string]any
Files map[string][]*multipart.FileHeader
Prefix string
TotalFormCount int
InitialFormCount int
MaxNum int
Errors []FormErrors
IsBound bool
}
BaseFormSet manages a collection of instances of a specific form.
func NewBaseFormSet ¶
func NewBaseFormSet(factory func() *Form, prefix string, total, initial, maxNum int) *BaseFormSet
NewBaseFormSet initializes a BaseFormSet.
func (*BaseFormSet) Bind ¶
func (fs *BaseFormSet) Bind(data map[string]any, files map[string][]*multipart.FileHeader)
Bind assigns data to all forms in the set.
func (*BaseFormSet) IsValid ¶
func (fs *BaseFormSet) IsValid() bool
IsValid runs validation on all forms.
type BaseWidget ¶
func (*BaseWidget) GetMedia ¶
func (w *BaseWidget) GetMedia() *Media
type CheckboxInput ¶
type CheckboxInput struct {
BaseWidget
}
CheckboxInput is `<input type="checkbox">`.
func NewCheckboxInput ¶
func NewCheckboxInput(attrs map[string]string) *CheckboxInput
func (*CheckboxInput) Render ¶
func (w *CheckboxInput) Render(name string, value any, attrs map[string]string) template.SafeString
type CheckboxSelectMultiple ¶
type CheckboxSelectMultiple struct {
BaseWidget
Choices []Choice
}
CheckboxSelectMultiple renders a list of checkboxes.
func NewCheckboxSelectMultiple ¶
func NewCheckboxSelectMultiple(choices []Choice, attrs map[string]string) *CheckboxSelectMultiple
func (*CheckboxSelectMultiple) Render ¶
func (w *CheckboxSelectMultiple) Render(name string, value any, attrs map[string]string) template.SafeString
type ChoiceField ¶
ChoiceField
type Field ¶
type Field interface {
Clean(value any) (any, error)
Widget() Widget
Required() bool
Label() string
HelpText() string
SetWidget(w Widget)
}
Field interface handles rendering and validation of a form field.
type Form ¶
type Form struct {
Fields map[string]Field
Data map[string]any
Files map[string][]*multipart.FileHeader
CleanedData map[string]any
Errors FormErrors
// Ordered fields for rendering
Order []string
IsBound bool
}
Form represents a collection of fields and their bound data.
func (*Form) NonFieldErrors ¶
NonFieldErrors returns errors not associated with a specific field.
func (*Form) Render ¶
func (f *Form) Render() template.SafeString
Render is a shortcut mapping to RenderTable.
func (*Form) RenderTable ¶
func (f *Form) RenderTable() template.SafeString
Render represents the form as a table structure.
type FormErrors ¶
FormErrors maps field names to lists of error messages.
type ImageField ¶
type ImageField struct {
FileField
}
type Input ¶
type Input struct {
BaseWidget
InputType string
}
Input is a generic `<input type="...">` widget.
func NewClearableFileInput ¶
ClearableFileInput extends FileInput allowing clearing the selection (simplified).
func NewDateInput ¶
DateInput is `<input type="date">`.
func NewDateTimeInput ¶
DateTimeInput is `<input type="datetime-local">`.
func NewEmailInput ¶
EmailInput is `<input type="email">`.
func NewFileInput ¶
FileInput is `<input type="file">`.
func NewHiddenInput ¶
HiddenInput is `<input type="hidden">`.
func NewNumberInput ¶
NumberInput is `<input type="number">`.
func NewPasswordInput ¶
PasswordInput is `<input type="password">`.
func NewTextInput ¶
TextInput is `<input type="text">`.
func NewTimeInput ¶
TimeInput is `<input type="time">`.
func NewURLInput ¶
URLInput is `<input type="url">`.
type Media ¶
Media handles CSS and JS files for a widget or form.
func (*Media) RenderCSS ¶
func (m *Media) RenderCSS() template.SafeString
RenderCSS outputs <link> tags.
func (*Media) RenderJS ¶
func (m *Media) RenderJS() template.SafeString
RenderJS outputs <script> tags.
type ModelForm ¶
type ModelForm struct {
Form
ModelType reflect.Type
Instance any
Includes []string
Excludes []string
}
ModelForm represents a form automatically generated from an ORM model.
func NewModelForm ¶
NewModelForm generates a new ModelForm based on the specified model struct instance.
type MultipleChoiceField ¶
MultipleChoiceField
type RadioSelect ¶
type RadioSelect struct {
CheckboxSelectMultiple // Logic is very similar
}
RadioSelect renders a list of radio buttons.
func NewRadioSelect ¶
func NewRadioSelect(choices []Choice, attrs map[string]string) *RadioSelect
func (*RadioSelect) Render ¶
func (w *RadioSelect) Render(name string, value any, attrs map[string]string) template.SafeString
type Select ¶
type Select struct {
BaseWidget
Choices []Choice
}
Select is `<select>...<option>...</select>`.
func NewNullBooleanSelect ¶
NullBooleanSelect is a Select with Yes/No/Unknown.
type SelectMultiple ¶
type SelectMultiple struct {
Select
}
SelectMultiple is `<select multiple>`.
func NewSelectMultiple ¶
func NewSelectMultiple(choices []Choice, attrs map[string]string) *SelectMultiple
type SplitDateTimeWidget ¶
type SplitDateTimeWidget struct {
BaseWidget
DateWidget Widget
TimeWidget Widget
}
SplitDateTimeWidget renders date and time separately.
func NewSplitDateTimeWidget ¶
func NewSplitDateTimeWidget(attrs map[string]string) *SplitDateTimeWidget
func (*SplitDateTimeWidget) Render ¶
func (w *SplitDateTimeWidget) Render(name string, value any, attrs map[string]string) template.SafeString
type Textarea ¶
type Textarea struct {
BaseWidget
}
Textarea is `<textarea>...</textarea>`.