forms

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lower

func Lower(_ context.Context, s string) (string, error)

func NotEmpty

func NotEmpty(_ context.Context, s string) (string, error)

func Strip

func Strip(_ context.Context, s string) (string, error)

Types

type Field

type Field struct {
	Name        string
	Type        string
	Label       string
	Description string

	Choices []Option
	Value   string
	Errors  []string

	Validators []FieldValidatorFunc
}

func NewHiddenField

func NewHiddenField(name string) Field

func NewPasswordField

func NewPasswordField(name, label string) Field

func NewSelectField

func NewSelectField(name, label string, choices []Option) Field

func NewTextField

func NewTextField(name, label string) Field

func (Field) WithDescription

func (f Field) WithDescription(s string) Field

func (Field) WithValidators

func (f Field) WithValidators(validators ...FieldValidatorFunc) Field

type FieldValidatorFunc

type FieldValidatorFunc func(context.Context, string) (string, error)

func EqualTo

func EqualTo(expected string) FieldValidatorFunc

func GoodQualityPassword

func GoodQualityPassword(minScore int, dictionary []string) FieldValidatorFunc

func MinLength

func MinLength(n int) FieldValidatorFunc

func OneOf

func OneOf(choices []Option) FieldValidatorFunc

type Form

type Form struct {
	Fields     []Field
	Errors     []string
	Validators []FormValidatorFunc
}

func (*Form) AddError

func (f *Form) AddError(err error)

func (*Form) Get

func (f *Form) Get(name string) string

func (*Form) GetField

func (f *Form) GetField(name string) Field

func (*Form) ValidateOnSubmit

func (f *Form) ValidateOnSubmit(req *http.Request) (*Form, bool)

func (*Form) WithDefaults

func (f *Form) WithDefaults(dflt map[string]string) *Form

type FormValidatorFunc

type FormValidatorFunc func(context.Context, *Form) error

func FormFieldsDiffer

func FormFieldsDiffer(a, b, errMsg string) FormValidatorFunc

func FormFieldsEqual

func FormFieldsEqual(a, b, errMsg string) FormValidatorFunc

type Option

type Option struct {
	Name  string
	Value string
}

Jump to

Keyboard shortcuts

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