Skip to content

Commit 4840829

Browse files
committed
update
1 parent ed55e9f commit 4840829

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Tags
170170

171171
Struct tags can be used to slightly modify automatic form creation. In particular the following tags are parsed:
172172

173-
* form_options: can contain the following keywords separated by comma
173+
* form_options: can contain the following keywords separated by Semicolon (;)
174174
- -: skip field, do not convert to HTML field
175175
- checked: for Checkbox fields, check by default
176176
- multiple: for select fields, allows multiple choices

common/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,7 @@ func ParseTmpl(data interface{}, fn_tpl template.FuncMap, fn_fixTpl func(tpls ..
123123
func Tag(t reflect.Type, fieldNo int, tagName string) string {
124124
return tagfast.Tag1(t, fieldNo, tagName)
125125
}
126+
127+
func Tago(t reflect.Type, f reflect.StructField, tagName string) (tag string, tf *tagfast.TagFast) {
128+
return tagfast.Tago(t, f, tagName)
129+
}

forms.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func (f *Form) SetModel(m interface{}) *Form {
6767
return f
6868
}
6969

70-
7170
func NewForm(style string, args ...string) *Form {
7271
if style == "" {
7372
style = formcommon.BASE
@@ -143,11 +142,20 @@ func unWindStructure(m interface{}, baseName string) ([]interface{}, string) {
143142
fieldSetList := make(map[string]*FieldSetType, 0)
144143
fieldSetSort := make(map[string]string, 0)
145144
for i := 0; i < t.NumField(); i++ {
146-
optionsArr := strings.Split(formcommon.Tag(t, i, "form_options"), ",")
147145
options := make(map[string]struct{})
148-
for _, opt := range optionsArr {
149-
if opt != "" {
150-
options[opt] = struct{}{}
146+
tag, tagf := formcommon.Tago(t, t.Field(i), "form_options")
147+
if tag != "" {
148+
var optionsArr []string = make([]string, 0)
149+
if tagf != nil {
150+
cached := tagf.GetParsed("form_options", func() interface{} {
151+
return strings.Split(formcommon.Tag(t, i, "form_options"), ";")
152+
})
153+
optionsArr = cached.([]string)
154+
}
155+
for _, opt := range optionsArr {
156+
if opt != "" {
157+
options[opt] = struct{}{}
158+
}
151159
}
152160
}
153161
if _, ok := options["-"]; !ok {

0 commit comments

Comments
 (0)