summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/admin/handlers.go5
-rw-r--r--system/api/create.go5
-rw-r--r--system/api/update.go5
-rw-r--r--system/db/config.go5
-rw-r--r--system/db/content.go47
5 files changed, 59 insertions, 8 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go
index aac9ec2..c70dd86 100644
--- a/system/admin/handlers.go
+++ b/system/admin/handlers.go
@@ -1860,7 +1860,6 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
// and correctly format for db storage. Essentially, we need
// fieldX.0: value1, fieldX.1: value2 => fieldX: []string{value1, value2}
fieldOrderValue := make(map[string]map[string][]string)
- ordVal := make(map[string][]string)
for k, v := range req.PostForm {
if strings.Contains(k, ".") {
fo := strings.Split(k, ".")
@@ -1868,7 +1867,9 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
// put the order and the field value into map
field := string(fo[0])
order := string(fo[1])
- fieldOrderValue[field] = ordVal
+ if len(fieldOrderValue[field]) == 0 {
+ fieldOrderValue[field] = make(map[string][]string)
+ }
// orderValue is 0:[?type=Thing&id=1]
orderValue := fieldOrderValue[field]
diff --git a/system/api/create.go b/system/api/create.go
index 3b748cc..8af415b 100644
--- a/system/api/create.go
+++ b/system/api/create.go
@@ -83,7 +83,6 @@ func createContentHandler(res http.ResponseWriter, req *http.Request) {
// and correctly format for db storage. Essentially, we need
// fieldX.0: value1, fieldX.1: value2 => fieldX: []string{value1, value2}
fieldOrderValue := make(map[string]map[string][]string)
- ordVal := make(map[string][]string)
for k, v := range req.PostForm {
if strings.Contains(k, ".") {
fo := strings.Split(k, ".")
@@ -91,7 +90,9 @@ func createContentHandler(res http.ResponseWriter, req *http.Request) {
// put the order and the field value into map
field := string(fo[0])
order := string(fo[1])
- fieldOrderValue[field] = ordVal
+ if len(fieldOrderValue[field]) == 0 {
+ fieldOrderValue[field] = make(map[string][]string)
+ }
// orderValue is 0:[?type=Thing&id=1]
orderValue := fieldOrderValue[field]
diff --git a/system/api/update.go b/system/api/update.go
index 36ffaeb..31f29c1 100644
--- a/system/api/update.go
+++ b/system/api/update.go
@@ -84,7 +84,6 @@ func updateContentHandler(res http.ResponseWriter, req *http.Request) {
// and correctly format for db storage. Essentially, we need
// fieldX.0: value1, fieldX.1: value2 => fieldX: []string{value1, value2}
fieldOrderValue := make(map[string]map[string][]string)
- ordVal := make(map[string][]string)
for k, v := range req.PostForm {
if strings.Contains(k, ".") {
fo := strings.Split(k, ".")
@@ -92,7 +91,9 @@ func updateContentHandler(res http.ResponseWriter, req *http.Request) {
// put the order and the field value into map
field := string(fo[0])
order := string(fo[1])
- fieldOrderValue[field] = ordVal
+ if len(fieldOrderValue[field]) == 0 {
+ fieldOrderValue[field] = make(map[string][]string)
+ }
// orderValue is 0:[?type=Thing&id=1]
orderValue := fieldOrderValue[field]
diff --git a/system/db/config.go b/system/db/config.go
index 5bb010a..c67fbe3 100644
--- a/system/db/config.go
+++ b/system/db/config.go
@@ -36,7 +36,6 @@ func SetConfig(data url.Values) error {
// and correctly format for db storage. Essentially, we need
// fieldX.0: value1, fieldX.1: value2 => fieldX: []string{value1, value2}
fieldOrderValue := make(map[string]map[string][]string)
- ordVal := make(map[string][]string)
for k, v := range data {
if strings.Contains(k, ".") {
fo := strings.Split(k, ".")
@@ -44,7 +43,9 @@ func SetConfig(data url.Values) error {
// put the order and the field value into map
field := string(fo[0])
order := string(fo[1])
- fieldOrderValue[field] = ordVal
+ if len(fieldOrderValue[field]) == 0 {
+ fieldOrderValue[field] = make(map[string][]string)
+ }
// orderValue is 0:[?type=Thing&id=1]
orderValue := fieldOrderValue[field]
diff --git a/system/db/content.go b/system/db/content.go
index 940c57b..e73d803 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -711,6 +711,53 @@ func postToJSON(ns string, data url.Values) ([]byte, error) {
}
post := t()
+ // check for any multi-value fields (ex. checkbox fields)
+ // and correctly format for db storage. Essentially, we need
+ // fieldX.0: value1, fieldX.1: value2 => fieldX: []string{value1, value2}
+ fieldOrderValue := make(map[string]map[string][]string)
+ for k, v := range data {
+ if strings.Contains(k, ".") {
+ fo := strings.Split(k, ".")
+
+ // put the order and the field value into map
+ field := string(fo[0])
+ order := string(fo[1])
+ if len(fieldOrderValue[field]) == 0 {
+ fieldOrderValue[field] = make(map[string][]string)
+ }
+
+ // orderValue is 0:[?type=Thing&id=1]
+ orderValue := fieldOrderValue[field]
+ orderValue[order] = v
+ fieldOrderValue[field] = orderValue
+
+ // discard the post form value with name.N
+ data.Del(k)
+ }
+ }
+
+ // add/set the key & value to the post form in order
+ for f, ov := range fieldOrderValue {
+ for i := 0; i < len(ov); i++ {
+ position := fmt.Sprintf("%d", i)
+ fieldValue := ov[position]
+
+ if data.Get(f) == "" {
+ for i, fv := range fieldValue {
+ if i == 0 {
+ data.Set(f, fv)
+ } else {
+ data.Add(f, fv)
+ }
+ }
+ } else {
+ for _, fv := range fieldValue {
+ data.Add(f, fv)
+ }
+ }
+ }
+ }
+
dec := schema.NewDecoder()
dec.SetAliasTag("json") // allows simpler struct tagging when creating a content type
dec.IgnoreUnknownKeys(true) // will skip over form values submitted, but not in struct