Skip to content

Commit

Permalink
minor fixes and remove debug line
Browse files Browse the repository at this point in the history
  • Loading branch information
donseba committed Feb 8, 2024
1 parent b81a44f commit d5062b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
# Dependency directories (remove the comment below to include it)
# vendor/
.idea/
example
6 changes: 6 additions & 0 deletions form.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func (f *Form) formRender(v interface{}, errs []FieldError, kv ...any) (template

return subhtml
},
"errors": func() []string {
if errs, ok := fieldErrors[field.Name]; ok {
return errs
}
return nil
},
})

fMap := copyMap(data)
Expand Down
18 changes: 13 additions & 5 deletions transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ func NewTransformer(model interface{}) (*Transformer, error) {

tr.Fields = fields

fmt.Printf("tr: %+v\n", tr.Fields)

return tr, nil
}

Expand All @@ -88,12 +86,12 @@ func (t *Transformer) scanModel(rValue reflect.Value, rType reflect.Type, names
tags := rType.Field(i).Tag

name := tags.Get(tagName)
fieldName := rType.Field(i).Name
if name == "" {
name = rType.Field(i).Name
name = fieldName
}

nname := append(names, name)

field := FormField{
Label: tags.Get(tagLabel),
Placeholder: tags.Get(tagPlaceholder),
Expand Down Expand Up @@ -228,7 +226,17 @@ func (t *Transformer) scanModel(rValue reflect.Value, rType reflect.Type, names
field.Step = "any"
}
case reflect.Bool:
field.Type = FieldTypeCheckbox
fieldType := FieldTypeCheckbox
if len(names) > 0 && names[len(names)-1] == name {
// radio-options use the same 'name' as their parent for grouping
fieldType = FieldTypeRadios
}

field.Type = fieldType

// replace last slice element with the field name
nname[len(nname)-1] = fieldName
field.Id = strings.Join(nname, ".")
case reflect.Slice, reflect.Array:
case reflect.Map:
case reflect.Struct:
Expand Down

0 comments on commit d5062b2

Please sign in to comment.