Added datalists

This commit is contained in:
Eduard Urbach 2017-10-22 00:17:35 +02:00
parent 664debf024
commit ae32a1a6cb
2 changed files with 10 additions and 4 deletions

View File

@ -13,10 +13,12 @@ component InputNumber(id string, value float64, label string, placeholder string
label(for=id)= label + ":"
input.widget-ui-element.action(id=id, data-field=id, type="number", value=value, min=min, max=max, step=step, placeholder=placeholder, title=placeholder, data-action="save", data-trigger="change")
component InputSelection(id string, value string, label string, placeholder string, values []string)
component InputSelection(id string, value string, label string, placeholder string, options []*arn.Option)
.widget-section
label(for=id)= label + ":"
select.widget-ui-element.action(id=id, data-field=id, value=value, title=placeholder, data-action="save", data-trigger="change")
each option in options
option(value=option.Value)= option.Label
component InputTags(id string, value []string, label string, tooltip string)
.widget-section

View File

@ -66,10 +66,14 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i
switch field.Type.String() {
case "string":
if field.Tag.Get("type") == "textarea" {
b.WriteString(components.InputTextArea(idPrefix+field.Name, fieldValue.String(), field.Name, ""))
if field.Tag.Get("datalist") != "" {
dataList := field.Tag.Get("datalist")
values := arn.DataLists[dataList]
b.WriteString(components.InputSelection(idPrefix+field.Name, fieldValue.String(), field.Name, field.Tag.Get("tooltip"), values))
} else if field.Tag.Get("type") == "textarea" {
b.WriteString(components.InputTextArea(idPrefix+field.Name, fieldValue.String(), field.Name, field.Tag.Get("tooltip")))
} else {
b.WriteString(components.InputText(idPrefix+field.Name, fieldValue.String(), field.Name, ""))
b.WriteString(components.InputText(idPrefix+field.Name, fieldValue.String(), field.Name, field.Tag.Get("tooltip")))
}
case "[]string":
b.WriteString(components.InputTags(idPrefix+field.Name, fieldValue.Interface().([]string), field.Name, field.Tag.Get("tooltip")))