form_builder

package module
v0.0.0-...-9495666 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 7 Imported by: 0

README

FormBuilder

example workflow name

Check out the test file for examples.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMessages = map[string]map[string]string{
	"en": {
		"Boolean": "%s has invalid boolean value",
		"Integer": "%s has invalid integer value",
		"Float":   "%s has invalid float value",

		"Required":     "%s is required",
		"EqualToField": "%s does not match %s",
	},
}
View Source
var Locale = "en"

Functions

func BoolValidator

func BoolValidator(_ *Form, f *Field) string

BoolValidator validates if a field has a valid boolean value according to strconv.ParseBool with the addition of the value "on" (for HTML checkboxes)

func FloatValidator

func FloatValidator(_ *Form, f *Field) string

FloatValidator validates if a field is a valid 64-bit float

func FormBuilder

func FormBuilder() *formBuilder

func IntValidator

func IntValidator(_ *Form, f *Field) string

IntValidator validates if a field is a valid 64-bit integer

func RequiredValidator

func RequiredValidator(fo *Form, fi *Field) string

func StringValidator

func StringValidator(_ *Form, _ *Field) string

StringValidator validates if a field is a valid string. All fields are valid strings :)

func UIntValidator

func UIntValidator(_ *Form, f *Field) string

UIntValidator validates if a field contains a valid 64-bit unsigned integer

Types

type Field

type Field struct {
	Label        string
	Validators   []FieldValidator
	Description  string
	ID           string
	DefaultValue []string
	Type         string

	// todo: not implemented yet
	Filters []FieldFilter
	Widget  Widget
	// contains filtered or unexported fields
}

func BoolField

func BoolField(label string, opts ...FieldOption) *Field

BoolField creates a new boolean type field

func DateField

func DateField(label string, format string, opts ...FieldOption) *Field

DateField creates a new date type field

func FloatField

func FloatField(label string, opts ...FieldOption) *Field

FloatField creates a new float type field

func IntField

func IntField(label string, opts ...FieldOption) *Field

IntField creates a new integer type field

func StrField

func StrField(label string, opts ...FieldOption) *Field

StrField creates a new string type field

func UIntField

func UIntField(label string, opts ...FieldOption) *Field

UIntField creates a new uint type field

func (*Field) Value

func (f *Field) Value() string

Value returns the first value associated with the field

func (*Field) Values

func (f *Field) Values() []string

Values returns all values of the field

type FieldFilter

type FieldFilter func(values []string) []string

type FieldOption

type FieldOption func(*Field)

func Description

func Description(desc string) FieldOption

Description adds a description to the field

func EqualToField

func EqualToField(fieldName string) FieldOption

EqualToField adds a EqualToFieldValidator to the field

func Filter

func Filter(filters ...FieldFilter) FieldOption

Filter adds filters to the field

func Required

func Required() FieldOption

Required adds a RequiredValidator to the field

func Validate

func Validate(validators ...FieldValidator) FieldOption

Validate appends validators to the field

type FieldValidator

type FieldValidator func(*Form, *Field) string

func DateValidator

func DateValidator(format string) FieldValidator

func EqualToFieldValidator

func EqualToFieldValidator(otherName string) FieldValidator

type Form

type Form struct {
	Fields map[string]*Field
	Errors ValidationErrors
}

func (*Form) Populate

func (f *Form) Populate(dst interface{}) error

func (*Form) Validate

func (f *Form) Validate() bool

func (*Form) ValuesMap

func (f *Form) ValuesMap() map[string][]string

type FormFillingFunc

type FormFillingFunc func(map[string][]string) Form

type FormValidator

type FormValidator func(*Form) string

type ValidationErrors

type ValidationErrors map[string][]string

type Widget

type Widget interface {
	Render() string
}

Jump to

Keyboard shortcuts

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