Improved reflection in editform

This commit is contained in:
2019-05-27 18:08:42 +09:00
parent ecfb9eea04
commit da3c064496
6 changed files with 46 additions and 45 deletions

View File

@ -106,7 +106,20 @@ func RenderField(b *strings.Builder, v *reflect.Value, field reflect.StructField
// Embedded fields
if field.Anonymous {
RenderObject(b, fieldValue.Interface(), idPrefix)
// If it's exported, render it normally.
if field.PkgPath == "" {
RenderObject(b, fieldValue.Interface(), idPrefix)
}
// If it's an unexported struct, we try to access the field names
// given to us from the anonymous struct on the actual object.
if field.Type.Kind() == reflect.Struct {
for i := 0; i < field.Type.NumField(); i++ {
f := field.Type.Field(i)
RenderField(b, v, f, idPrefix)
}
}
return
}