Documentation
¶
Overview ¶
Package formrules parses validation tags and checks submitted form values against them. kit uses it at run time; codegen uses it to write the same rules for the browser, where packages/tern/src/runtime/validate.ts applies them with the same messages. testdata/cases.json keeps the two in step.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(f Field, values []string, other func(name string) string, labelOf func(name string) string) string
Check returns why the posted values of f are invalid, or "". values are the field's posted values; other returns another field's first value, for same=.
func Humanize ¶
Humanize turns a field name into a label: "firstName" and "first_name" become "First name".
Types ¶
type Field ¶
type Field struct {
Name string `json:"name"`
Label string `json:"label"`
Kind Kind `json:"kind"`
Required bool `json:"required,omitempty"`
Rules []Rule `json:"rules,omitempty"`
// Message replaces every failure message for the field.
Message string `json:"message,omitempty"`
// Secret fields, such as passwords, are never sent back to refill a form.
Secret bool `json:"secret,omitempty"`
// contains filtered or unexported fields
}
Field is a form field's rules.
func FromReflect ¶
FromReflect reads the fields of a struct type for decoding and checking.
type Kind ¶
type Kind string
Kind is how a field's text is read.
const ( String Kind = "string" Int Kind = "int" Float Kind = "float" Bool Kind = "bool" Date Kind = "date" // YYYY-MM-DD DateTime Kind = "datetime" // YYYY-MM-DDTHH:MM, as datetime-local inputs post Strings Kind = "strings" // several values, such as checkboxes with one name )
The kinds of field, from the Go type: text, whole and decimal numbers, checkboxes, dates and lists.