package builder import ( "html" "golang-fave/engine/utils" "golang-fave/engine/wrapper" ) const ( DFKHidden = iota DFKText DFKNumber DFKEmail DFKPassword DFKTextArea DFKCheckBox DFKSubmit DFKMessage ) type DataFormField struct { Caption string Kind int Name string Value string Placeholder string Hint string Target string Required bool Classes string Min string Max string CallBack func(field *DataFormField) string } func DataForm(wrap *wrapper.Wrapper, data []DataFormField) string { var html_hidden string var html_element string var html_message string var html_button string for i, field := range data { if field.Kind == DFKHidden { if field.CallBack != nil { html_hidden += field.CallBack(&field) } else { html_hidden += `` } } else if field.Kind != DFKHidden && field.Kind != DFKSubmit && field.Kind != DFKMessage { if field.CallBack != nil { html_element += field.CallBack(&field) } else { required := `` if field.Required { required = ` required` } classes := field.Classes if classes != "" { classes = " " + classes } html_element += `
` html_element += `
` html_element += `
` if field.Kind != DFKCheckBox { html_element += `` } else { html_element += `` } html_element += `
` html_element += `
` html_element += `
` if field.Kind == DFKText { html_element += `` } else if field.Kind == DFKNumber { html_element += `` } else if field.Kind == DFKEmail { html_element += `` } else if field.Kind == DFKPassword { html_element += `` } else if field.Kind == DFKTextArea { html_element += `` } else if field.Kind == DFKCheckBox { checked := "" if field.Value != "0" { checked = " checked" } html_element += `
` } html_element += `
` if field.Hint != "" { html_element += `
` + field.Hint + `
` } html_element += `
` html_element += `
` html_element += `
` } } else if field.Kind == DFKMessage { if field.CallBack != nil { html_message += field.CallBack(&field) } else { html_message += `
` html_message += `
` html_message += `
` html_message += `
` html_message += `
` html_message += `
` html_message += `
` } } else if field.Kind == DFKSubmit { if field.CallBack != nil { html_button += field.CallBack(&field) } else { html_button += `
` html_button += `
` html_button += ` ` html_button += `
` html_button += `
` html_button += `
` html_button += `
` html_button += `
` } } } if html_hidden != "" { html_hidden = `` } return `
` + html_hidden + html_element + html_message + html_button + `
` }