Change HTMLInputType to use reflect Kind

This commit is contained in:
David Vogel 2023-07-06 22:13:52 +02:00
parent 66b229c929
commit 4fa06b747c

View File

@ -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:
return "text" // We will render the boolean as text, as this is an input field, not a checkbox.
case *string:
}
v := reflect.ValueOf(f.Value)
switch v.Kind() {
case reflect.Pointer, reflect.Interface:
if v.IsNil() {
return "text"
case *int, *int8, *int16, *int32, *int64, *uint, *uint8, *uint16, *uint32, *uint64:
}
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 reflect.String:
return "text"
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"
}