12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package form
- import (
- "context"
- "strconv"
- )
- // ValidatorFunc defines a function for FormField data validation
- type ValidatorFunc func(FormField, context.Context) error
- // ValidatorsList defines a list of ValidatorFunc
- type ValidatorsList []ValidatorFunc
- // A general purpose form field struct
- type FormField struct {
- Name string
- Type string
- Label string
- Value string
- Error error
- Validators *ValidatorsList
- }
- // GetString returns FormField.Value as string
- func (f FormField) GetString() string {
- return f.Value
- }
- // GetInt returns FormField.Value as int
- func (f FormField) GetInt() (int, error) {
- return strconv.Atoi(f.Value)
- }
- // GetFloat returns FormField.Value as float
- func (f FormField) GetFloat() (float64, error) {
- return strconv.ParseFloat(f.Value, 64)
- }
- // GetBool returns boolean value for checkbox fields
- func (f FormField) GetBool() (bool, error) {
- // placeholder
- return false, nil
- }
|