Change Input/TextArea ValueBinder interface

fixes #1
This commit is contained in:
David Vogel 2024-12-30 13:54:41 +01:00
parent 200feb5bbc
commit 2619cb9e06
4 changed files with 7 additions and 5 deletions

View File

@ -1,5 +1,6 @@
{ {
"cSpell.words": [ "cSpell.words": [
"borderless",
"Dadido", "Dadido",
"datetime", "datetime",
"domrender", "domrender",
@ -7,6 +8,7 @@
"ldflags", "ldflags",
"Segoe", "Segoe",
"simplehttp", "simplehttp",
"Sprintf",
"Typer", "Typer",
"vgrouter", "vgrouter",
"Vogel", "Vogel",

View File

@ -9,12 +9,12 @@ import (
type TextArea struct { type TextArea struct {
AttrMap vugu.AttrMap AttrMap vugu.AttrMap
Bind *string Bind ValueBinder
} }
func (c *TextArea) content() string { func (c *TextArea) content() string {
if c.Bind != nil { if c.Bind != nil {
return *c.Bind return c.Bind.StringValue()
} }
return "" return ""
@ -24,6 +24,6 @@ func (c *TextArea) handleChange(event vugu.DOMEvent) {
val := event.PropString("target", "value") val := event.PropString("target", "value")
if c.Bind != nil { if c.Bind != nil {
*c.Bind = val c.Bind.SetStringValue(val) // TODO: Error is omitted, we should show it
} }
} }

View File

@ -122,7 +122,7 @@
<input:Tags :Bind="input.ListBindGenericSlice[string]{Slice: &c.tags1Slice}" id="page-tags-1"></input:Tags> <input:Tags :Bind="input.ListBindGenericSlice[string]{Slice: &c.tags1Slice}" id="page-tags-1"></input:Tags>
<h2>Text-area</h2> <h2>Text-area</h2>
<input:TextArea :Bind="&c.textArea1" id="page-text-area-1" rows="10" style="width:100%; resize:none; box-sizing:border-box;"></input:TextArea> <input:TextArea :Bind="input.ValueBindAny{&c.textArea1}" id="page-text-area-1" rows="10" style="width:100%; resize:none; box-sizing:border-box;"></input:TextArea>
<pre vg-content='fmt.Sprintf("Your entered text: %s", c.textArea1)'></pre> <pre vg-content='fmt.Sprintf("Your entered text: %s", c.textArea1)'></pre>
</layout:Container> </layout:Container>

View File

@ -1272,7 +1272,7 @@ func (c *PageInput) Build(vgin *vugu.BuildIn) (vgout *vugu.BuildOut) {
vgin.BuildEnv.WireComponent(vgcomp) vgin.BuildEnv.WireComponent(vgcomp)
} }
vgin.BuildEnv.UseComponent(vgcompKey, vgcomp) // ensure we can use this in the cache next time around vgin.BuildEnv.UseComponent(vgcompKey, vgcomp) // ensure we can use this in the cache next time around
vgcomp.Bind = &c.textArea1 vgcomp.Bind = input.ValueBindAny{&c.textArea1}
vgcomp.AttrMap = make(map[string]interface{}, 8) vgcomp.AttrMap = make(map[string]interface{}, 8)
vgcomp.AttrMap["id"] = "page-text-area-1" vgcomp.AttrMap["id"] = "page-text-area-1"
vgcomp.AttrMap["rows"] = "10" vgcomp.AttrMap["rows"] = "10"