Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
459b9785
authored
2013-08-11 22:42:35 +0800
by
miraclesu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
renderform ignore struct field if form tag value is '-'
1 parent
5c859466
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
utils.go
utils_test.go
utils.go
View file @
459b978
...
...
@@ -282,20 +282,24 @@ func RenderForm(obj interface{}) template.HTML {
fieldT
:=
objT
.
Field
(
i
)
tags
:=
strings
.
Split
(
fieldT
.
Tag
.
Get
(
"form"
),
","
)
name
:=
fieldT
.
Name
if
len
(
tags
)
<
2
{
fType
:=
"text"
if
len
(
tags
)
>
0
&&
tags
[
0
]
==
"-"
{
continue
}
if
len
(
tags
)
==
1
&&
len
(
tags
[
0
])
>
0
{
name
=
tags
[
0
]
}
raw
=
append
(
raw
,
fmt
.
Sprintf
(
`%v: <input name="%v" type="text" value="%v">`
,
fieldT
.
Name
,
name
,
fieldV
.
Interface
()))
}
else
{
}
else
if
len
(
tags
)
>=
2
{
if
len
(
tags
[
0
])
>
0
{
name
=
tags
[
0
]
}
raw
=
append
(
raw
,
fmt
.
Sprintf
(
`%v: <input name="%v" type="%v" value="%v">`
,
f
ieldT
.
Name
,
name
,
tags
[
1
],
fieldV
.
Interface
()))
if
len
(
tags
[
1
])
>
0
{
f
Type
=
tags
[
1
]
}
}
raw
=
append
(
raw
,
fmt
.
Sprintf
(
`%v: <input name="%v" type="%v" value="%v">`
,
fieldT
.
Name
,
name
,
fType
,
fieldV
.
Interface
()))
}
return
template
.
HTML
(
strings
.
Join
(
raw
,
"</br>"
))
}
...
...
utils_test.go
View file @
459b978
...
...
@@ -150,10 +150,11 @@ func TestParseForm(t *testing.T) {
func
TestRenderForm
(
t
*
testing
.
T
)
{
type
user
struct
{
Id
int
tag
string
`form:
tag
`
Id
int
`form:"-"`
tag
string
`form:
"tag"
`
Name
interface
{}
`form:"username"`
Age
int
`form:"age,text"`
Sex
string
Email
[]
string
Intro
string
`form:",textarea"`
}
...
...
@@ -165,9 +166,9 @@ func TestRenderForm(t *testing.T) {
}
output
=
RenderForm
(
&
u
)
result
:=
template
.
HTML
(
`Id: <input name="Id" type="text" value="0"></br>`
+
`Name: <input name="username" type="text" value="test"></br>`
+
`Age: <input name="age" type="text" value="0"></br>`
+
`Sex: <input name="Sex" type="text" value=""></br>`
+
`Intro: <input name="Intro" type="textarea" value="">`
)
if
output
!=
result
{
t
.
Errorf
(
"output should equal `%v` but got `%v`"
,
result
,
output
)
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment