engine: resources: Display tick marks for input range

This makes it prettier. We should also add the values, but this is
harder to do nicely.
This commit is contained in:
James Shubin
2025-09-14 20:52:45 -04:00
parent a66cbc3098
commit 045aa8820c

View File

@@ -36,6 +36,7 @@ import (
"net/http"
"net/url"
"sort"
"strconv"
"syscall/js"
"time"
@@ -186,16 +187,39 @@ func (obj *Main) Run() error {
el.Set("type", inputType)
if inputType == common.HTTPServerUIInputTypeRange {
min := 0
max := 0
step := 1
if val, exists := x.Type[common.HTTPServerUIInputTypeRangeMin]; exists {
if d, err := strconv.Atoi(val); err == nil {
min = d
el.Set("min", val)
}
}
if val, exists := x.Type[common.HTTPServerUIInputTypeRangeMax]; exists {
if d, err := strconv.Atoi(val); err == nil {
max = d
el.Set("max", val)
}
}
if val, exists := x.Type[common.HTTPServerUIInputTypeRangeStep]; exists {
if d, err := strconv.Atoi(val); err == nil {
step = d
el.Set("step", val)
}
}
// add the tick marks
el.Call("setAttribute", "list", id) // Use setAttribute (NOT Set)
datalist := obj.document.Call("createElement", "datalist")
datalist.Set("id", id) // matches the id of the list field
for i := min; i <= max; i += step {
fmt.Printf("i: %+v\n", i)
option := obj.document.Call("createElement", "option")
option.Set("value", i)
datalist.Call("appendChild", option)
}
fieldset.Call("appendChild", datalist)
}
el.Set("value", element.Value) // XXX: here or after change handler?