1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 19:00:55 +00:00

Adds html5 input types to valid intput types of RenderForm.

This commit is contained in:
Vangelis Tsoumenis 2014-06-30 10:38:32 +02:00
parent 4994d36b66
commit 34572193c6

View File

@ -371,6 +371,7 @@ func RenderForm(obj interface{}) template.HTML {
return template.HTML(strings.Join(raw, "</br>")) return template.HTML(strings.Join(raw, "</br>"))
} }
// renderFormField returns a string containing HTML of a single form field.
func renderFormField(label, name, fType string, value interface{}) string { func renderFormField(label, name, fType string, value interface{}) string {
if isValidForInput(fType) { if isValidForInput(fType) {
return fmt.Sprintf(`%v<input name="%v" type="%v" value="%v">`, label, name, fType, value) return fmt.Sprintf(`%v<input name="%v" type="%v" value="%v">`, label, name, fType, value)
@ -379,8 +380,9 @@ func renderFormField(label, name, fType string, value interface{}) string {
return fmt.Sprintf(`%v<%v name="%v">%v</%v>`, label, fType, name, value, fType) return fmt.Sprintf(`%v<%v name="%v">%v</%v>`, label, fType, name, value, fType)
} }
// isValidForInput checks if fType is a valid value for the `type` property of an HTML input element.
func isValidForInput(fType string) bool { func isValidForInput(fType string) bool {
validInputTypes := strings.Fields("text password checkbox radio submit reset hidden image file button") validInputTypes := strings.Fields("text password checkbox radio submit reset hidden image file button search email url tel number range date month week time datetime datetime-local color")
for _, validType := range validInputTypes { for _, validType := range validInputTypes {
if fType == validType { if fType == validType {
return true return true
@ -389,7 +391,6 @@ func isValidForInput(fType string) bool {
return false return false
} }
// parseFormTag takes the stuct-tag of a StructField and parses the `form` value. // parseFormTag takes the stuct-tag of a StructField and parses the `form` value.
// returned are the form label, name-property, type and wether the field should be ignored. // returned are the form label, name-property, type and wether the field should be ignored.
func parseFormTag(fieldT reflect.StructField) (label, name, fType string, ignored bool) { func parseFormTag(fieldT reflect.StructField) (label, name, fType string, ignored bool) {