Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
e0393b72
Commit
e0393b72
authored
Jun 30, 2016
by
Joshua Santos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change meta to required, and refactor a bit to cover edge cases
parent
84b6bef7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
templatefunc.go
templatefunc.go
+3
-6
templatefunc_test.go
templatefunc_test.go
+18
-6
No files found.
templatefunc.go
View file @
e0393b72
...
...
@@ -475,13 +475,10 @@ func parseFormTag(fieldT reflect.StructField) (label, name, fType string, id str
id
=
fieldT
.
Tag
.
Get
(
"id"
)
class
=
fieldT
.
Tag
.
Get
(
"class"
)
meta
:=
strings
.
Split
(
fieldT
.
Tag
.
Get
(
"meta"
),
","
)
required
=
false
switch
len
(
meta
)
{
case
1
:
if
len
(
meta
[
0
])
>
0
&&
meta
[
0
]
!=
"-"
{
required
=
true
}
required_field
:=
fieldT
.
Tag
.
Get
(
"required"
)
if
required_field
!=
"-"
&&
required_field
!=
""
{
required
,
_
=
strconv
.
ParseBool
(
required_field
)
}
switch
len
(
tags
)
{
...
...
templatefunc_test.go
View file @
e0393b72
...
...
@@ -214,12 +214,14 @@ func TestRenderFormField(t *testing.T) {
func
TestParseFormTag
(
t
*
testing
.
T
)
{
// create struct to contain field with different types of struct-tag `form`
type
user
struct
{
All
int
`form:"name,text,年龄:"`
NoName
int
`form:",hidden,年龄:"`
OnlyLabel
int
`form:",,年龄:"`
OnlyName
int
`form:"name" id:"name" class:"form-name"`
Ignored
int
`form:"-"`
Required
int
`form:"name" meta:"true"`
All
int
`form:"name,text,年龄:"`
NoName
int
`form:",hidden,年龄:"`
OnlyLabel
int
`form:",,年龄:"`
OnlyName
int
`form:"name" id:"name" class:"form-name"`
Ignored
int
`form:"-"`
Required
int
`form:"name" required:"true"`
IgnoreRequired
int
`form:"name"`
NotRequired
int
`form:"name" required:"false"`
}
objT
:=
reflect
.
TypeOf
(
&
user
{})
.
Elem
()
...
...
@@ -255,6 +257,16 @@ func TestParseFormTag(t *testing.T) {
t
.
Errorf
(
"Form Tag containing only name and required was not correctly parsed."
)
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
6
))
if
!
(
name
==
"name"
&&
required
==
false
)
{
t
.
Errorf
(
"Form Tag containing only name and ignore required was not correctly parsed."
)
}
label
,
name
,
fType
,
id
,
class
,
ignored
,
required
=
parseFormTag
(
objT
.
Field
(
7
))
if
!
(
name
==
"name"
&&
required
==
false
)
{
t
.
Errorf
(
"Form Tag containing only name and not required was not correctly parsed."
)
}
}
func
TestMapGet
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment