()
| 74 | func (fm *Form) WidgetValue() any { return &fm.Struct } |
| 75 | |
| 76 | func (fm *Form) getStructFields() { |
| 77 | var fields []*structField |
| 78 | |
| 79 | shouldShow := func(parent reflect.Value, field reflect.StructField) bool { |
| 80 | if field.Tag.Get("display") == "-" { |
| 81 | return false |
| 82 | } |
| 83 | if ss, ok := reflectx.UnderlyingPointer(parent).Interface().(ShouldDisplayer); ok { |
| 84 | fm.isShouldDisplayer = true |
| 85 | if !ss.ShouldDisplay(field.Name) { |
| 86 | return false |
| 87 | } |
| 88 | } |
| 89 | return true |
| 90 | } |
| 91 | |
| 92 | reflectx.WalkFields(reflectx.Underlying(reflect.ValueOf(fm.Struct)), |
| 93 | func(parent reflect.Value, field reflect.StructField, value reflect.Value) bool { |
| 94 | return shouldShow(parent, field) |
| 95 | }, |
| 96 | func(parent reflect.Value, parentField *reflect.StructField, field reflect.StructField, value reflect.Value) { |
| 97 | if field.Tag.Get("display") == "add-fields" && field.Type.Kind() == reflect.Struct { |
| 98 | reflectx.WalkFields(value, |
| 99 | func(parent reflect.Value, sfield reflect.StructField, value reflect.Value) bool { |
| 100 | return shouldShow(parent, sfield) |
| 101 | }, |
| 102 | func(parent reflect.Value, parentField *reflect.StructField, sfield reflect.StructField, value reflect.Value) { |
| 103 | // if our parent field is read only, we must also be |
| 104 | if field.Tag.Get("edit") == "-" && sfield.Tag.Get("edit") == "" { |
| 105 | sfield.Tag += ` edit:"-"` |
| 106 | } |
| 107 | fields = append(fields, &structField{path: field.Name + " • " + sfield.Name, field: sfield, value: value, parent: parent}) |
| 108 | }) |
| 109 | } else { |
| 110 | fields = append(fields, &structField{path: field.Name, field: field, value: value, parent: parent}) |
| 111 | } |
| 112 | }) |
| 113 | fm.structFields = fields |
| 114 | } |
| 115 | |
| 116 | func (fm *Form) Init() { |
| 117 | fm.Frame.Init() |
no test coverage detected