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
a37b2bdf
authored
2013-08-12 06:46:40 +0800
by
miraclesu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Support custom label for renderform
1 parent
50f3bd58
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
utils.go
utils_test.go
utils.go
View file @
a37b2bd
...
...
@@ -281,24 +281,39 @@ func RenderForm(obj interface{}) template.HTML {
fieldT
:=
objT
.
Field
(
i
)
tags
:=
strings
.
Split
(
fieldT
.
Tag
.
Get
(
"form"
),
","
)
label
:=
fieldT
.
Name
+
": "
name
:=
fieldT
.
Name
fType
:=
"text"
if
len
(
tags
)
>
0
&&
tags
[
0
]
==
"-"
{
continue
}
if
len
(
tags
)
==
1
&&
len
(
tags
[
0
])
>
0
{
name
=
tags
[
0
]
}
else
if
len
(
tags
)
>=
2
{
switch
len
(
tags
)
{
case
1
:
if
tags
[
0
]
==
"-"
{
continue
}
if
len
(
tags
[
0
])
>
0
{
name
=
tags
[
0
]
}
case
2
:
if
len
(
tags
[
0
])
>
0
{
name
=
tags
[
0
]
}
if
len
(
tags
[
1
])
>
0
{
fType
=
tags
[
1
]
}
case
3
:
if
len
(
tags
[
0
])
>
0
{
name
=
tags
[
0
]
}
if
len
(
tags
[
1
])
>
0
{
fType
=
tags
[
1
]
}
if
len
(
tags
[
2
])
>
0
{
label
=
tags
[
2
]
}
}
raw
=
append
(
raw
,
fmt
.
Sprintf
(
`%v: <input name="%v" type="%v" value="%v">`
,
fieldT
.
Name
,
name
,
fType
,
fieldV
.
Interface
()))
raw
=
append
(
raw
,
fmt
.
Sprintf
(
`%v<input name="%v" type="%v" value="%v">`
,
label
,
name
,
fType
,
fieldV
.
Interface
()))
}
return
template
.
HTML
(
strings
.
Join
(
raw
,
"</br>"
))
}
...
...
utils_test.go
View file @
a37b2bd
...
...
@@ -153,7 +153,7 @@ func TestRenderForm(t *testing.T) {
Id
int
`form:"-"`
tag
string
`form:"tag"`
Name
interface
{}
`form:"username"`
Age
int
`form:"age,text"`
Age
int
`form:"age,text
,年龄:
"`
Sex
string
Email
[]
string
Intro
string
`form:",textarea"`
...
...
@@ -167,7 +167,7 @@ func TestRenderForm(t *testing.T) {
output
=
RenderForm
(
&
u
)
result
:=
template
.
HTML
(
`Name: <input name="username" type="text" value="test"></br>`
+
`
Age:
<input name="age" type="text" value="0"></br>`
+
`
年龄:
<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
{
...
...
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