2023-05-25 13:59:13 +00:00
|
|
|
package input
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vugu/vugu"
|
|
|
|
)
|
|
|
|
|
2023-05-25 20:55:42 +00:00
|
|
|
// Field is a text or number based input component.
|
2023-05-25 13:59:13 +00:00
|
|
|
// The HTML input type is determined by the bound data type.
|
|
|
|
type Field struct {
|
|
|
|
AttrMap vugu.AttrMap
|
|
|
|
|
|
|
|
Bind FieldBinder
|
|
|
|
|
|
|
|
DefaultSlot vugu.Builder
|
|
|
|
|
|
|
|
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.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)
|
|
|
|
}
|
|
|
|
}
|