From 5748ccb3a271d710e0ed34366eced0062c4fae3e Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 18 Aug 2022 08:48:52 +0200 Subject: [PATCH] Form: se data='' allora nil. --- form.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/form.go b/form.go index 51b3327..8d33b0a 100644 --- 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 -- 2.49.0