diff --git a/utils/editform/editform.go b/utils/editform/editform.go index 1a05598d..49fe976c 100644 --- a/utils/editform/editform.go +++ b/utils/editform/editform.go @@ -115,76 +115,7 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i // String if fieldType == "string" { - idType := field.Tag.Get("idType") - - // Try to infer the ID type by the field name - if idType == "" { - switch field.Name { - case "AnimeID": - idType = "Anime" - - case "CharacterID": - idType = "Character" - } - } - - showPreview := idType != "" && fieldValue.String() != "" - - if showPreview { - b.WriteString("
") - } - + renderStringField(b, v, field, idPrefix, fieldValue) return } @@ -218,46 +149,7 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i // Any kind of array if strings.HasPrefix(fieldType, "[]") { - b.WriteString(` `) + renderSliceField(b, v, field, idPrefix, fieldType, fieldValue) return } @@ -273,6 +165,123 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i b.WriteString(``) } +// String field +func renderStringField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, idPrefix string, fieldValue reflect.Value) { + idType := field.Tag.Get("idType") + + // Try to infer the ID type by the field name + if idType == "" { + switch field.Name { + case "AnimeID": + idType = "Anime" + + case "CharacterID": + idType = "Character" + } + } + + showPreview := idType != "" && fieldValue.String() != "" + + if showPreview { + b.WriteString(" ") + } +} + +// Slice field +func renderSliceField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, idPrefix string, fieldType string, fieldValue reflect.Value) { + b.WriteString(` `) +} + // findMainID finds the main ID of the object. func findMainID(t reflect.Type, v reflect.Value) reflect.Value { idField := v.FieldByName("ID")