David Vogel
11199f5e0d
- Add Type field to input.Field that can override the input type - Add support for time.Time to input.Field - Update example PageInput
49 lines
830 B
Go
49 lines
830 B
Go
package input
|
|
|
|
import (
|
|
"github.com/vugu/vugu"
|
|
)
|
|
|
|
// Field is a text or number based input component.
|
|
// The HTML input type is determined by the bound data type.
|
|
type Field struct {
|
|
AttrMap vugu.AttrMap
|
|
ID string // The ID of the internal input component.
|
|
|
|
Bind FieldBinder
|
|
|
|
DefaultSlot vugu.Builder
|
|
|
|
Type string // Overrides the type of the input component.
|
|
|
|
err error // Current error caused by any invalid input.
|
|
}
|
|
|
|
func (c *Field) content() string {
|
|
if c.Bind != nil {
|
|
return c.Bind.String()
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
func (c *Field) inputType() string {
|
|
if c.Type != "" {
|
|
return c.Type
|
|
}
|
|
|
|
if c.Bind != nil {
|
|
return c.Bind.HTMLInputType()
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
func (c *Field) handleChange(event vugu.DOMEvent) {
|
|
val := event.PropString("target", "value")
|
|
|
|
if c.Bind != nil {
|
|
c.err = c.Bind.SetString(val)
|
|
}
|
|
}
|