Documentation ¶
Index ¶
- Constants
- Variables
- func AttachValues(form *Form) error
- func BindUrlValues(form *Form, values url.Values) error
- func BoolToStr(v interface{}) (string, bool)
- func Configure(l *goapp.Lifecycle, conf *config.Config)
- func GetEmbedFS() embed.FS
- func NumberToStr(v interface{}) (string, bool)
- func PrepareForm(form *Form) error
- func Process(form *Form, request *http.Request) error
- func StrToBool(value interface{}) (bool, bool)
- func StrToNumber(value string, kind reflect.Kind) (interface{}, bool)
- func StrToValue(value interface{}, src reflect.Value) (interface{}, bool)
- func Val[T FormTypes](form *Form, name string) T
- func ValidateForm(form *Form) error
- func ValueToStr(value interface{}, src reflect.Value) (string, bool)
- func ValueToStrSlice(value interface{}, src reflect.Value) ([]string, bool)
- type Attributes
- type Error
- type FieldCollectionOptions
- type FieldCollectionValue
- type FieldOption
- type FieldOptions
- type Form
- type FormField
- func (f *FormField) Add(name string, options ...interface{}) *FormField
- func (f *FormField) AddValidator(validator Validator) *FormField
- func (f *FormField) AddValidators(validators ...Validator) *FormField
- func (f *FormField) Get(name string) *FormField
- func (f *FormField) RemoveValidator(code string) *FormField
- func (f *FormField) ResetValidators() *FormField
- func (f *FormField) SetAutocomplete(value string) *FormField
- func (f *FormField) SetAutocorrect(value bool) *FormField
- func (f *FormField) SetAutofocus(value bool) *FormField
- func (f *FormField) SetChecked(value bool) *FormField
- func (f *FormField) SetClass(value string) *FormField
- func (f *FormField) SetHeight(value uint16) *FormField
- func (f *FormField) SetHelp(value string) *FormField
- func (f *FormField) SetList(value string) *FormField
- func (f *FormField) SetMarshaller(marshaller Marshaller) *FormField
- func (f *FormField) SetMax(max interface{}) *FormField
- func (f *FormField) SetMaxLength(value uint32) *FormField
- func (f *FormField) SetMin(min interface{}) *FormField
- func (f *FormField) SetMinLength(value uint32) *FormField
- func (f *FormField) SetModule(value string) *FormField
- func (f *FormField) SetMultiple(value bool) *FormField
- func (f *FormField) SetNovalidation(value bool) *FormField
- func (f *FormField) SetPattern(value string) *FormField
- func (f *FormField) SetPlaceholder(value string) *FormField
- func (f *FormField) SetReadonly(value bool) *FormField
- func (f *FormField) SetRequired(value bool) *FormField
- func (f *FormField) SetSize(value uint16) *FormField
- func (f *FormField) SetStep(value uint32) *FormField
- func (f *FormField) SetTemplate(value string) *FormField
- func (f *FormField) SetType(value string) *FormField
- func (f *FormField) SetUnmarshaller(unmarshaller Unmarshaller) *FormField
- func (f *FormField) SetWidth(value uint16) *FormField
- func (f *FormField) Value(name string) interface{}
- type FormTypes
- type Input
- type Label
- type Marshaller
- type MarshallerResult
- type Unmarshaller
- type Validator
- func EmailValidator() Validator
- func MaxLengthValidator(max uint32, mode string) Validator
- func MaxValidator[T number](max T) Validator
- func MinLengthValidator(min uint32, mode string) Validator
- func MinValidator[T number](min T) Validator
- func OptionsValidator() Validator
- func RequiredValidator() Validator
- func UrlValidator() Validator
- type ValidatorFunc
Constants ¶
View Source
const ( ENC_TYPE_URLENCODED = "application/x-www-form-urlencoded" ENC_TYPE_MULTIPART = "multipart/form-data" )
View Source
const ( Initialized = iota Prepared Submitted Validated Processed )
Variables ¶
View Source
var ( ErrInvalidType = errors.New("value does not match the expected type") ErrConvertValue = errors.New("unable to convert value to the correct type") ErrNoOptions = errors.New("no options found") )
View Source
var ( ErrNoValue = errors.New("unable to find the value") ErrInvalidSubmittedData = errors.New("invalid submitted data") )
View Source
var ( ErrValidationError = errors.New("the form is not valid") ErrRequiredValidator = errors.New("the value is required") ErrEmailValidator = errors.New("the value is not a valid email") ErrUrlValidator = errors.New("the value is not a valid url") ErrMaxValidator = errors.New("the value is too big") ErrMinValidator = errors.New("the value is too small") ErrOptionsValidator = errors.New("the value is not in the list of options") )
View Source
var (
ErrInvalidState = errors.New("invalid state")
)
View Source
var (
ErrNoTemplate = errors.New("unable to find the template to render")
)
Functions ¶
func AttachValues ¶
Iterate over all submitted values and assign them to the related data structure if possible. This will not work work if the form has some errors.
func BindUrlValues ¶
Iterate over all fields and bind the submitted values to the SubmittedValue field in the form. This will not attach the value to the underlying data structure, use AttachValues for this.
This will call all unmarshallers defined on each form field.
func GetEmbedFS ¶
func NumberToStr ¶
func PrepareForm ¶
Iterate over all fields and call the marshaller function to transform the Go value into a serialized value used in the HTML form. This also setup the different attribures required by the HTML form.
func StrToValue ¶
func ValidateForm ¶
Types ¶
type Attributes ¶
type FieldCollectionOptions ¶
type FieldCollectionOptions struct { Items []*FieldCollectionValue Configure func(value interface{}) *Form }
type FieldCollectionValue ¶
type FieldCollectionValue struct { Value interface{} Key string }
type FieldOption ¶
type FieldOptions ¶
type FieldOptions []*FieldOption
type Form ¶
type Form struct { Data interface{} Fields []*FormField HasErrors bool Locale string EncType string Method string Action string State int // contains filtered or unexported fields }
func CreateForm ¶
func CreateForm(data interface{}) *Form
type FormField ¶
type FormField struct { Prefix string // used for nested forms Name string Module string Help string Attributes Attributes Label Label Input Input Error Error Mandatory bool InitialValue interface{} SubmittedValue interface{} Children []*FormField Touched bool Submitted bool Errors []string HasErrors bool Validators []Validator Marshaller Marshaller // from go to serialized Unmarshaller Unmarshaller // from serialized to go Options interface{} // contains filtered or unexported fields }
func CreateFormField ¶
func CreateFormField() *FormField
func (*FormField) AddValidator ¶
func (*FormField) AddValidators ¶
func (*FormField) RemoveValidator ¶
func (*FormField) ResetValidators ¶
func (*FormField) SetAutocomplete ¶
func (*FormField) SetAutocorrect ¶
func (*FormField) SetAutofocus ¶
func (*FormField) SetChecked ¶
func (*FormField) SetMarshaller ¶
func (f *FormField) SetMarshaller(marshaller Marshaller) *FormField
func (*FormField) SetMaxLength ¶
func (*FormField) SetMinLength ¶
func (*FormField) SetMultiple ¶
func (*FormField) SetNovalidation ¶
func (*FormField) SetPattern ¶
func (*FormField) SetPlaceholder ¶
func (*FormField) SetReadonly ¶
func (*FormField) SetRequired ¶
func (*FormField) SetTemplate ¶
func (*FormField) SetUnmarshaller ¶
func (f *FormField) SetUnmarshaller(unmarshaller Unmarshaller) *FormField
type Input ¶
type Input struct { Name string Template string Class string Style string Value string Placeholder string // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#placeholder Type string Id string Pattern string // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#pattern List string Autocomplete string // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete Spellcheck string Readonly bool Disabled bool Checked bool Multiple bool Required bool Autofocus bool Autocorrect bool Novalidate bool Size uint16 MinLength uint32 MaxLength uint32 Min interface{} Max interface{} Step uint32 Height uint16 Width uint16 Options FieldOptions }
type Marshaller ¶
type MarshallerResult ¶
type MarshallerResult struct { Marshaller Marshaller Unmarshaller Unmarshaller Type string }
type Validator ¶
func EmailValidator ¶
func EmailValidator() Validator
func MaxLengthValidator ¶
func MaxValidator ¶
func MaxValidator[T number](max T) Validator
func MinLengthValidator ¶
func MinValidator ¶
func MinValidator[T number](min T) Validator
func OptionsValidator ¶
func OptionsValidator() Validator
func RequiredValidator ¶
func RequiredValidator() Validator
func UrlValidator ¶
func UrlValidator() Validator
type ValidatorFunc ¶
type ValidatorFunc struct {
// contains filtered or unexported fields
}
func (*ValidatorFunc) Code ¶
func (v *ValidatorFunc) Code() string
Click to show internal directories.
Click to hide internal directories.