func BuildSelectOptions(valueMaps []map[string]interface{}, defaultValue interface{}, valueField string, labelField string, addFields ...string) string { options := "" for _, valueMap := range valueMaps { optionValue, ok := valueMap[valueField] if !ok { continue } optionValueStr := u.ToStr(optionValue) optionLabel, _ := valueMap[labelField] optionDatas := "" for _, addField := range addFields { addData := u.GetStringValue(valueMap, addField) optionDatas = optionDatas + fmt.Sprintf(`data-wb-a-%s = "%s" `, addField, addData) } if optionValue == defaultValue { options = options + fmt.Sprintf(`<option value="%s" %s selected>%s</option>`, optionValueStr, optionDatas, optionLabel) continue } options = options + fmt.Sprintf(`<option value="%s" %s>%s</option>`, optionValueStr, optionDatas, optionLabel) } return options }
func createFromGroup(field itemDef.Field, valueMap map[string]interface{}, statusMap map[string]string) string { value, ok := valueMap[field.Name] if !ok { return "" } status, sok := statusMap[field.Name] if !sok { status = "" } var fromGroup string switch field.Input { case "textarea": fromGroup = fmt.Sprintf(textareaFormat, field.Label, field.Require, field.Label, field.Name, field.Name, status, value, field.Name) case "text": fromGroup = fmt.Sprintf(textFormat, field.Label, field.Require, field.Label, field.Name, field.Name, u.ToStr(value), status, field.Name) case "static": fromGroup = fmt.Sprintf(staticFormat, field.Label, value) case "money": fromGroup = fmt.Sprintf(moneyFormat, field.Label, field.Require, field.Label, field.Name, field.Name, u.ToStr(value), status, field.Name) case s.TFloat: fromGroup = fmt.Sprintf(floatFormat, field.Label, field.Require, field.Label, field.Name, field.Name, u.ToStr(value), status, field.Name) case s.Percent: fromGroup = fmt.Sprintf(percentFormat, field.Label, field.Require, field.Label, field.Name, field.Name, u.ToStr(value), status, field.Name) case "date", "datetime": // fmt.Println("date", field.Name, value) fromGroup = fmt.Sprintf(dateFormate, field.Label, field.Require, field.Label, field.Name, field.Name, value, status, field.Name) case s.Password: fromGroup = fmt.Sprintf(passwordFormat, field.Label, field.Require, field.Label, field.Name, field.Name, "*****", status, field.Name) case s.Hidden: fromGroup = fmt.Sprintf(hiddenFormat, field.Name, field.Name, value) case "select": var options string for _, option := range field.Enum { if option.Sn == value { options = options + fmt.Sprintf(`<option value="%s" selected>%s</option>`, option.Sn, option.Label) continue } options = options + fmt.Sprintf(`<option value="%s">%s</option>`, option.Sn, option.Label) } fromGroup = fmt.Sprintf(selectFormat, field.Label, field.Require, field.Label, field.Name, field.Name, field.Default, status, options, field.Name) case s.Autocomplete: key, kok := valueMap[field.Name+s.EKey] if !kok { key = "" } name, nok := valueMap[field.Name+s.EName] if !nok { name = "" } fromGroup = fmt.Sprintf(autocompleteFormat, field.Label, field.Name, key, status, field.Label, field.Name, field.Name, field.Require, field.Label, name, field.Name, field.Name, value) case s.Upload: fromGroup = fmt.Sprintf(uploadFormat, field.Label, field.Name, field.Name, status) case "none": fromGroup = "" default: beego.Error(fmt.Sprintf("FromBuilder.createFormGroup input %s type: %s not support ", field.Name, field.Input)) fromGroup = "" } return fromGroup }