6c9ff81f by WithGJR

fix: if user didn't set id or class, then it won't be displayed in HTML code

1 parent 1b3e7de4
...@@ -380,11 +380,19 @@ func RenderForm(obj interface{}) template.HTML { ...@@ -380,11 +380,19 @@ func RenderForm(obj interface{}) template.HTML {
380 380
381 // renderFormField returns a string containing HTML of a single form field. 381 // renderFormField returns a string containing HTML of a single form field.
382 func renderFormField(label, name, fType string, value interface{}, id string, class string) string { 382 func renderFormField(label, name, fType string, value interface{}, id string, class string) string {
383 if id != "" {
384 id = "id=\"" + id + "\""
385 }
386
387 if class != "" {
388 class = "class=\"" + class + "\""
389 }
390
383 if isValidForInput(fType) { 391 if isValidForInput(fType) {
384 return fmt.Sprintf(`%v<input id="%v" class="%v" name="%v" type="%v" value="%v">`, label, id, class, name, fType, value) 392 return fmt.Sprintf(`%v<input %v %v name="%v" type="%v" value="%v">`, label, id, class, name, fType, value)
385 } 393 }
386 394
387 return fmt.Sprintf(`%v<%v id="%v" class="%v" name="%v">%v</%v>`, label, fType, id, class, name, value, fType) 395 return fmt.Sprintf(`%v<%v %v %v name="%v">%v</%v>`, label, fType, id, class, name, value, fType)
388 } 396 }
389 397
390 // isValidForInput checks if fType is a valid value for the `type` property of an HTML input element. 398 // isValidForInput checks if fType is a valid value for the `type` property of an HTML input element.
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!