From 34572193c6ebb493815776c14fa82340e54648f4 Mon Sep 17 00:00:00 2001 From: Vangelis Tsoumenis Date: Mon, 30 Jun 2014 10:38:32 +0200 Subject: [PATCH] Adds html5 input types to valid intput types of RenderForm. --- templatefunc.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templatefunc.go b/templatefunc.go index ea98470a..274e3af9 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -371,6 +371,7 @@ func RenderForm(obj interface{}) template.HTML { return template.HTML(strings.Join(raw, "
")) } +// renderFormField returns a string containing HTML of a single form field. func renderFormField(label, name, fType string, value interface{}) string { if isValidForInput(fType) { return fmt.Sprintf(`%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`, 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 { - 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 { if fType == validType { return true @@ -389,7 +391,6 @@ func isValidForInput(fType string) bool { return false } - // 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. func parseFormTag(fieldT reflect.StructField) (label, name, fType string, ignored bool) {