-
Notifications
You must be signed in to change notification settings - Fork 3
/
forms_test.go
89 lines (85 loc) · 1.54 KB
/
forms_test.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package forms
import (
"fmt"
"testing"
"github.com/coscms/forms/common"
"github.com/coscms/forms/config"
"github.com/webx-top/com"
)
func TestForms(t *testing.T) {
type Data struct {
Test string
}
mp := map[string]interface{}{
`name`: `test`,
`age`: 20,
`items`: map[string]string{
`itemK1`: `itemV1`,
},
`data`: &Data{
Test: `test-data`,
},
`list`: []string{
`1`, `2`,
},
`listData`: []*Data{
&Data{
Test: `test-listdata-1`,
}, &Data{
Test: `test-listdata-2`,
},
},
}
cfg := NewConfig()
cfg.AddElement(&config.Element{
ID: `input-name`,
Type: `text`,
Name: `name`,
Label: `名称`,
}, &config.Element{
ID: `input-items-k1`,
Type: `text`,
Name: `items[itemK1]`,
Label: `Item K1`,
}, &config.Element{
ID: `input-data-test`,
Type: `text`,
Name: `data.test`,
Label: `Data`,
}, &config.Element{
ID: `input-list-0`,
Type: `text`,
Name: `list.0`,
Label: `List 0`,
}, &config.Element{
ID: `input-list-2`,
Type: `text`,
Name: `list.2`,
Label: `List 2`,
}, &config.Element{
ID: `input-listdata-0`,
Type: `text`,
Name: `listData.0.test`,
Label: `ListData 0`,
})
form := NewWithModelConfig(mp, cfg)
com.Dump(form.Data())
result := form.String()
fmt.Println(result)
}
func TestParseConfig(t *testing.T) {
cfg := config.Config{
Elements: []*config.Element{
{
ID: ``,
Type: `text`,
Name: `test`,
},
},
}
f := NewForms(New())
f.Theme = common.BOOTSTRAP
f.Init(&cfg)
f.ParseFromConfig(true)
com.Dump(cfg.Clone())
}