Form: se data='' allora nil.
authorAndrea Zagli <azagli@libero.it>
Thu, 18 Aug 2022 06:48:52 +0000 (08:48 +0200)
committerAndrea Zagli <azagli@libero.it>
Thu, 18 Aug 2022 06:48:52 +0000 (08:48 +0200)
form.go

diff --git a/form.go b/form.go
index 51b332792fa0d24391369766c3b4d2787326ea02..8d33b0ac2dda0ab0f4335ffd22f3e1edc6c61872 100644 (file)
--- a/form.go
+++ b/form.go
@@ -230,13 +230,17 @@ func CreaMapDb (elems map[string]*FormElement) (map[string]interface{}) {
                                /* tolgo la formattazione */
                                campi[elem.DBName] = strings.ReplaceAll(elem.Value, ".", "")
                                campi[elem.DBName] = strings.ReplaceAll(campi[elem.DBName].(string), ",", ".")
-                       } else if strings.Contains(elem.Validation, "mydate") && elem.Value != "" {
+                       } else if strings.Contains(elem.Validation, "mydate") {
                                /* metto la data in formato sql */
-                               t, err := time.Parse("02/01/2006", elem.Value)
-                               if err == nil {
-                                       campi[elem.DBName] = t.Format("2006-01-02")
+                               if elem.Value == "" {
+                                       campi[elem.DBName] = nil
                                } else {
-                                       fmt.Println(err)
+                                       t, err := time.Parse("02/01/2006", elem.Value)
+                                       if err == nil {
+                                               campi[elem.DBName] = t.Format("2006-01-02")
+                                       } else {
+                                               fmt.Println(err)
+                                       }
                                }
                        } else {
                                campi[elem.DBName] = elem.Value