From 4553386032f9c5fb7b535a0903420e89982e199c Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Wed, 17 Aug 2022 12:25:47 +0200 Subject: [PATCH] Form: il validator date deve accettare come valido il campo vuoto. --- form.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/form.go b/form.go index ba47984..22fa73c 100644 --- 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, "-") -- 2.49.0