Skip to content

Commit 2594607

Browse files
committed
update
1 parent 76d11ad commit 2594607

File tree

4 files changed

+60
-53
lines changed

4 files changed

+60
-53
lines changed

config/field_interface.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package config
2+
3+
import (
4+
"html/template"
5+
)
6+
7+
// FieldInterface defines the interface an object must implement to be used in a form. Every method returns a FieldInterface object
8+
// to allow methods chaining.
9+
type FieldInterface interface {
10+
Name() string
11+
OriginalName() string
12+
Cols() int
13+
SetName(string)
14+
SetLabelCols(cols int)
15+
SetFieldCols(cols int)
16+
Render() template.HTML
17+
AddClass(class string) FieldInterface
18+
RemoveClass(class string) FieldInterface
19+
AddTag(class string) FieldInterface
20+
RemoveTag(class string) FieldInterface
21+
SetID(id string) FieldInterface
22+
SetParam(key string, value interface{}) FieldInterface
23+
DeleteParam(key string) FieldInterface
24+
AddCSS(key, value string) FieldInterface
25+
RemoveCSS(key string) FieldInterface
26+
SetTheme(theme string) FieldInterface
27+
SetLabel(label string) FieldInterface
28+
AddLabelClass(class string) FieldInterface
29+
RemoveLabelClass(class string) FieldInterface
30+
SetValue(value string) FieldInterface
31+
Disabled() FieldInterface
32+
Enabled() FieldInterface
33+
SetTemplate(tmpl string, theme ...string) FieldInterface
34+
SetHelptext(text string) FieldInterface
35+
AddError(err string) FieldInterface
36+
MultipleChoice() FieldInterface
37+
SingleChoice() FieldInterface
38+
AddSelected(opt ...string) FieldInterface
39+
SetSelected(opt ...string) FieldInterface
40+
RemoveSelected(opt string) FieldInterface
41+
AddChoice(key, value interface{}, checked ...bool) FieldInterface
42+
SetChoices(choices interface{}, saveIndex ...bool) FieldInterface
43+
SetText(text string) FieldInterface
44+
SetData(key string, value interface{})
45+
Data() map[string]interface{}
46+
String() string
47+
SetLang(lang string)
48+
Lang() string
49+
Clone() FormElement
50+
51+
Element() *Element
52+
}

config/utils.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package config
22

3-
import "github.com/coscms/forms/fields"
4-
53
const (
64
STATIC = "static"
75
Disabled = "disabled"
@@ -52,7 +50,7 @@ func setDefaultValue(elements []*Element, languages []*Language, fieldDefaultVal
5250
}
5351
for _, lang := range languages {
5452
elem.Value = fieldDefaultValue(lang.Name(elem.Name))
55-
if field, ok := lang.Field(elem.Name).(fields.FieldInterface); ok {
53+
if field, ok := lang.Field(elem.Name).(FieldInterface); ok {
5654
field.SetValue(elem.Value)
5755
}
5856
}

fields/field_interface.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,9 @@
11
package fields
22

33
import (
4-
"html/template"
5-
64
"github.com/coscms/forms/config"
75
)
86

97
// FieldInterface defines the interface an object must implement to be used in a form. Every method returns a FieldInterface object
108
// to allow methods chaining.
11-
type FieldInterface interface {
12-
Name() string
13-
OriginalName() string
14-
Cols() int
15-
SetName(string)
16-
SetLabelCols(cols int)
17-
SetFieldCols(cols int)
18-
Render() template.HTML
19-
AddClass(class string) FieldInterface
20-
RemoveClass(class string) FieldInterface
21-
AddTag(class string) FieldInterface
22-
RemoveTag(class string) FieldInterface
23-
SetID(id string) FieldInterface
24-
SetParam(key string, value interface{}) FieldInterface
25-
DeleteParam(key string) FieldInterface
26-
AddCSS(key, value string) FieldInterface
27-
RemoveCSS(key string) FieldInterface
28-
SetTheme(theme string) FieldInterface
29-
SetLabel(label string) FieldInterface
30-
AddLabelClass(class string) FieldInterface
31-
RemoveLabelClass(class string) FieldInterface
32-
SetValue(value string) FieldInterface
33-
Disabled() FieldInterface
34-
Enabled() FieldInterface
35-
SetTemplate(tmpl string, theme ...string) FieldInterface
36-
SetHelptext(text string) FieldInterface
37-
AddError(err string) FieldInterface
38-
MultipleChoice() FieldInterface
39-
SingleChoice() FieldInterface
40-
AddSelected(opt ...string) FieldInterface
41-
SetSelected(opt ...string) FieldInterface
42-
RemoveSelected(opt string) FieldInterface
43-
AddChoice(key, value interface{}, checked ...bool) FieldInterface
44-
SetChoices(choices interface{}, saveIndex ...bool) FieldInterface
45-
SetText(text string) FieldInterface
46-
SetData(key string, value interface{})
47-
Data() map[string]interface{}
48-
String() string
49-
SetLang(lang string)
50-
Lang() string
51-
Clone() config.FormElement
52-
53-
Element() *config.Element
54-
}
9+
type FieldInterface = config.FieldInterface

forms_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
package forms
1+
package forms_test
22

33
import (
44
"fmt"
55
"testing"
66

7+
"github.com/coscms/forms"
78
"github.com/coscms/forms/common"
89
"github.com/coscms/forms/config"
10+
_ "github.com/coscms/forms/defaults"
911
"github.com/webx-top/com"
1012
)
1113

@@ -33,7 +35,7 @@ func TestForms(t *testing.T) {
3335
},
3436
},
3537
}
36-
cfg := NewConfig()
38+
cfg := forms.NewConfig()
3739
cfg.AddElement(&config.Element{
3840
ID: `input-name`,
3941
Type: `text`,
@@ -65,7 +67,7 @@ func TestForms(t *testing.T) {
6567
Name: `listData.0.test`,
6668
Label: `ListData 0`,
6769
})
68-
form := NewWithModelConfig(mp, cfg)
70+
form := forms.NewWithModelConfig(mp, cfg)
6971
com.Dump(form.Data())
7072
result := form.String()
7173
fmt.Println(result)
@@ -81,7 +83,7 @@ func TestParseConfig(t *testing.T) {
8183
},
8284
},
8385
}
84-
f := NewForms(New())
86+
f := forms.NewForms(forms.New())
8587
f.Theme = common.BOOTSTRAP
8688
f.Init(&cfg)
8789
f.ParseFromConfig(true)

0 commit comments

Comments
 (0)