summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-09-30 20:10:43 -0400
committerSteve Manuel <nilslice@gmail.com>2016-09-30 20:10:43 -0400
commitf2a151f2696e92d27f1e674bc02850dff7d3cd3c (patch)
tree79f9d55110054ae112ac56c91c07e9df7730ef82
parent285281dc2ab1f4426f91bd01c9345cd7f7d6d599 (diff)
refactor input attrs on Checkbox to be more logical
-rw-r--r--management/editor/elements.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/management/editor/elements.go b/management/editor/elements.go
index c1c418b..4ea0be0 100644
--- a/management/editor/elements.go
+++ b/management/editor/elements.go
@@ -117,11 +117,15 @@ func Checkbox(fieldName string, p interface{}, attrs, options map[string]string)
i := 0
for k, v := range options {
+ inputAttrs := map[string]string{
+ "type": "checkbox",
+ "value": k,
+ }
+
// check if k is in the pre-checked values and set to checked
- var val string
for _, x := range checked {
if k == x {
- val = "true"
+ inputAttrs["checked"] = "true"
}
}
@@ -129,22 +133,13 @@ func Checkbox(fieldName string, p interface{}, attrs, options map[string]string)
// func since this is for a multi-value name
input := &element{
TagName: "input",
- Attrs: map[string]string{
- "type": "checkbox",
- "checked": val,
- "value": k,
- },
+ Attrs: inputAttrs,
Name: tagNameFromStructFieldMulti(fieldName, i, p),
label: v,
data: "",
viewBuf: &bytes.Buffer{},
}
- // if checked == false, delete it from input.Attrs for clarity
- if input.Attrs["checked"] == "" {
- delete(input.Attrs, "checked")
- }
-
opts = append(opts, input)
i++
}