Commit 6c9ff81f authored by WithGJR's avatar WithGJR

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

parent 1b3e7de4
......@@ -380,11 +380,19 @@ func RenderForm(obj interface{}) template.HTML {
// renderFormField returns a string containing HTML of a single form field.
func renderFormField(label, name, fType string, value interface{}, id string, class string) string {
if id != "" {
id = "id=\"" + id + "\""
}
if class != "" {
class = "class=\"" + class + "\""
}
if isValidForInput(fType) {
return fmt.Sprintf(`%v<input id="%v" class="%v" name="%v" type="%v" value="%v">`, label, id, class, name, fType, value)
return fmt.Sprintf(`%v<input %v %v name="%v" type="%v" value="%v">`, label, id, class, name, fType, value)
}
return fmt.Sprintf(`%v<%v id="%v" class="%v" name="%v">%v</%v>`, label, fType, id, class, name, value, fType)
return fmt.Sprintf(`%v<%v %v %v name="%v">%v</%v>`, label, fType, id, class, name, value, fType)
}
// isValidForInput checks if fType is a valid value for the `type` property of an HTML input element.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment