]> saetta.ns0.it Git - zakegg_go/commitdiff
Form: il validator date deve accettare come valido il campo vuoto.
authorAndrea Zagli <azagli@libero.it>
Wed, 17 Aug 2022 10:25:47 +0000 (12:25 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 17 Aug 2022 10:25:47 +0000 (12:25 +0200)
form.go

diff --git a/form.go b/form.go
index ba47984a7fa0dd69eb85e5d2428b0885e859b399..22fa73c62b1264b4f65114d873c97c96718292f5 100644 (file)
--- a/form.go
+++ b/form.go
@@ -68,7 +68,12 @@ func ValidatorDate(fl validator.FieldLevel) bool {
        fmt.Printf("DUMP param %+v\n", fl.Param())
        fmt.Printf("DUMP tag %+v\n", fl.GetTag())
 
-       v, _ := time.Parse("02/01/2006", fmt.Sprintf("%s", fl.Field()))
+       val := strings.Trim(fmt.Sprintf("%s", fl.Field()), " ")
+       if val == "" {
+               return true
+       }
+
+       v, _ := time.Parse("02/01/2006", val)
 
        params := fl.Param()
        p := strings.Split(params, "-")