forked from kirves/go-form-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.go
27 lines (22 loc) · 757 Bytes
/
static.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package fields
import (
"fmt"
"reflect"
"github.com/bkrn/go-form-it/common"
)
// // Static field type
// type StaticType struct {
// Field
// }
// StaticField returns a static field with the provided name and content
func StaticField(name, content string) *Field {
ret := FieldWithType(name, formcommon.STATIC)
ret.SetText(content)
return ret
}
// RadioFieldFromInstance creates and initializes a radio field based on its name, the reference object instance and field number.
// It uses i object's [fieldNo]-th field content (if any) to set the field content.
func StaticFieldFromInstance(i interface{}, fieldNo int, name string) *Field {
ret := StaticField(name, fmt.Sprintf("%s", reflect.ValueOf(i).Field(fieldNo).Interface()))
return ret
}