See README.md for the consolidated API. This file contains additional detail.
f, err := form.New("content", data) // data implements fmt.Fielder
// -> f.GetID() == "content." + resolveStructName(data)
// -> f.RenderHTML() renders all fields that have a Widget in data.Schema()For each field in data.Schema():
field.IsPK() && field.IsAutoInc()→ skip (auto-increment PKs not editable).field.Widget == nil→ skip (no UI binding).field.Widget.Clone(formID, fieldName).(input.Input)→ positioned input.field.NotNull→SetRequired(true)on the input.- Current value bound via
fmt.ReadValues()+SetValues().
- Skips fields with
SkipValidationset to true in the input. - Uses
GetSelectedValue()to get current value per input. - Calls
inp.Validate(val)(promoted fromfmt.Widget). - Returns the first error encountered.
Synchronizes input values back to the struct pointers provided by data.Pointers().
Supports fmt.FieldText, fmt.FieldInt, fmt.FieldFloat, and fmt.FieldBool.
Validates the provided data using the form's input rules. Satisfies crudp.DataValidator.
type Permitted struct {
Letters bool // a-z, A-Z (and ñ/Ñ)
Tilde bool // á, é, í, ó, ú
Numbers bool // 0-9
Spaces bool // ' '
BreakLine bool // '\n'
Tab bool // '\t'
Extra []rune // additional allowed characters
NotAllowed []string // disallowed substrings
Minimum int // minimum length
Maximum int // maximum length
}Error messages from Permitted.Validate(name, text):
"{name} minimum {min} chars"— value shorter than Minimum"{name} maximum {max} chars"— value longer than Maximum"space not allowed"— space when Spaces=false"character {X} not allowed"— disallowed character
Fielder types can optionally implement Namer to provide a custom form name:
type Namer interface {
FormName() string
}If not implemented, defaults to "form".