Documentation ¶
Overview ¶
Package multiforms processes returned HTML forms that may contain child forms.
Acknowledgement: the origin of this code is the book Let's Go! by Alex Edwards. This version adds support for child forms.
Index ¶
- Variables
- type Child
- type Form
- func (f *Form) ChildBool(field string, ix int) bool
- func (f *Form) ChildFile(field string, i int, ix int, validType func(string) bool) string
- func (f *Form) ChildFloat(field string, i int, ix int, min float64, max float64, precision float64) (n float64, s string)
- func (f *Form) ChildGet(field string, i int) string
- func (f *Form) ChildIndex(field string, i int) (int, error)
- func (f *Form) ChildMin(field string, i int, ix int, min int) int
- func (f *Form) ChildPositive(field string, i int, ix int) int
- func (f *Form) ChildRequired(field string, i int, ix int) string
- func (f *Form) ChildSelect(field string, i int, ix int, nOptions int) (int, error)
- func (f *Form) ChildText(field string, i int, ix int, min int, max int) string
- func (f *Form) ChildTrimmed(field string, i int) string
- func (f *Form) Float(s string, field string, min float64, max float64) float64
- func (f *Form) MatchesPattern(field string, pattern *regexp.Regexp)
- func (f *Form) MaxLength(field string, d int)
- func (f *Form) MinLength(field string, d int)
- func (f *Form) NChildItems() int
- func (f *Form) PermittedValues(field string, opts ...string)
- func (f *Form) Positive(field string) int
- func (f *Form) Required(fields ...string)
- func (f *Form) Valid() bool
Constants ¶
This section is empty.
Variables ¶
var EmailRX = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
EmailRX is a regular expression for an email address, as recommended by W3C and Web Hypertext Application Technology Working Group.
var WebFiles embed.FS
WebFiles are the package's web resources (templates and static files)
Functions ¶
This section is empty.
Types ¶
type Child ¶
Child specifies a child form.
func (*Child) ChildError ¶
ChildError returns the error for a child field
func (*Child) ChildStyle ¶
ChildStyle gets the display attribute for child item - hidden for a child form template.
func (*Child) ChildValid ¶
ChildValid returns a CSS class to indicate if a field is valid, for Bootstrap.
type Form ¶
Form holds form data (in url.Values) and validation errors.
func (*Form) ChildBool ¶
ChildBool returns a checkbox value from child form. Unlike other fields, only checked fields are returned, and the value is the child index.
func (*Form) ChildFloat ¶ added in v1.3.1
func (f *Form) ChildFloat(field string, i int, ix int, min float64, max float64, precision float64) (n float64, s string)
ChildFloat accepts a floating point number with a minimum and maximum values from a child form. The precision specifies the maximum precision accepted: 0 = any, 1 = whole number, 0.5 = half values, 0.1 = tenths, etc. It allows blank values, and returns both the number and a tidily formatted string.
func (*Form) ChildIndex ¶
ChildIndex returns the index of a child form. Indexes are used to match the returned child items against the original data.
func (*Form) ChildPositive ¶
ChildPositive returns a positive number from a child form.
func (*Form) ChildRequired ¶
ChildRequired is deprecated. Use ChildText.
func (*Form) ChildSelect ¶
ChildSelect returns of the value of an HTML select. It assumes values are integers, 0 ... nOption-1
func (*Form) ChildText ¶ added in v0.11.0
ChildText returns trimmed text a child form, validating the value length. Set min=1 for a required value, max<=0 for no upper size.
func (*Form) ChildTrimmed ¶
ChildTrimmed is deprecated. Use ChildText.
func (*Form) MatchesPattern ¶
MatchesPattern checks that a field matches a regular expression.
func (*Form) MaxLength ¶
MaxLength checks that a field does not exceed a maximum number of characters.
func (*Form) NChildItems ¶
NChildItems returns the number of child items in the form.
func (*Form) PermittedValues ¶
PermittedValues checks that a specific field in the form matches one of a set of specific permitted values.