Adds html5 input types to valid intput types of RenderForm.
Showing
1 changed file
with
3 additions
and
2 deletions
| ... | @@ -371,6 +371,7 @@ func RenderForm(obj interface{}) template.HTML { | ... | @@ -371,6 +371,7 @@ func RenderForm(obj interface{}) template.HTML { |
| 371 | return template.HTML(strings.Join(raw, "</br>")) | 371 | return template.HTML(strings.Join(raw, "</br>")) |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | // renderFormField returns a string containing HTML of a single form field. | ||
| 374 | func renderFormField(label, name, fType string, value interface{}) string { | 375 | func renderFormField(label, name, fType string, value interface{}) string { |
| 375 | if isValidForInput(fType) { | 376 | if isValidForInput(fType) { |
| 376 | return fmt.Sprintf(`%v<input name="%v" type="%v" value="%v">`, label, name, fType, value) | 377 | 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 { | ... | @@ -379,8 +380,9 @@ func renderFormField(label, name, fType string, value interface{}) string { |
| 379 | return fmt.Sprintf(`%v<%v name="%v">%v</%v>`, label, fType, name, value, fType) | 380 | return fmt.Sprintf(`%v<%v name="%v">%v</%v>`, label, fType, name, value, fType) |
| 380 | } | 381 | } |
| 381 | 382 | ||
| 383 | // isValidForInput checks if fType is a valid value for the `type` property of an HTML input element. | ||
| 382 | func isValidForInput(fType string) bool { | 384 | func isValidForInput(fType string) bool { |
| 383 | validInputTypes := strings.Fields("text password checkbox radio submit reset hidden image file button") | 385 | 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") |
| 384 | for _, validType := range validInputTypes { | 386 | for _, validType := range validInputTypes { |
| 385 | if fType == validType { | 387 | if fType == validType { |
| 386 | return true | 388 | return true |
| ... | @@ -389,7 +391,6 @@ func isValidForInput(fType string) bool { | ... | @@ -389,7 +391,6 @@ func isValidForInput(fType string) bool { |
| 389 | return false | 391 | return false |
| 390 | } | 392 | } |
| 391 | 393 | ||
| 392 | |||
| 393 | // parseFormTag takes the stuct-tag of a StructField and parses the `form` value. | 394 | // parseFormTag takes the stuct-tag of a StructField and parses the `form` value. |
| 394 | // returned are the form label, name-property, type and wether the field should be ignored. | 395 | // returned are the form label, name-property, type and wether the field should be ignored. |
| 395 | func parseFormTag(fieldT reflect.StructField) (label, name, fType string, ignored bool) { | 396 | func parseFormTag(fieldT reflect.StructField) (label, name, fType string, ignored bool) { | ... | ... |
-
Please register or sign in to post a comment