From 4fa06b747c40300a30594645974c3203499aeb6a Mon Sep 17 00:00:00 2001 From: David Vogel Date: Thu, 6 Jul 2023 22:13:52 +0200 Subject: [PATCH] Change HTMLInputType to use reflect Kind --- components/input/value-binder.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/components/input/value-binder.go b/components/input/value-binder.go index c420c44..72c7498 100644 --- a/components/input/value-binder.go +++ b/components/input/value-binder.go @@ -73,16 +73,29 @@ func (f ValueBindAny) SetStringValue(value string) error { } func (f ValueBindAny) HTMLInputType() string { - switch f.Value.(type) { + switch v := f.Value.(type) { + case HTMLInputTyper: // Support nested values. + return v.HTMLInputType() case *time.Time: return "datetime-local" - case *bool: + } + + v := reflect.ValueOf(f.Value) + switch v.Kind() { + case reflect.Pointer, reflect.Interface: + if v.IsNil() { + return "text" + } + return ValueBindAny{Value: v.Elem().Interface()}.HTMLInputType() + case reflect.Bool: return "text" // We will render the boolean as text, as this is an input field, not a checkbox. - case *string: + case reflect.String: return "text" - case *int, *int8, *int16, *int32, *int64, *uint, *uint8, *uint16, *uint32, *uint64: + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return "number" - case *float32, *float64: + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return "number" + case reflect.Float32, reflect.Float64: return "number" }