Open init-database opened 9 months ago
This ilustrate my problem:
type Parent struct { Childs []Child validate:"dive" }
validate:"dive"
type Child struct { JustAField string validate:"customValidation" }
validate:"customValidation"
func customValidation(fl validator.FieldLevel) bool { // here I want to get the index of child // which currently being validated }
errs := validate.Struct(Parent) I cannot find a method to get current index of child inside customValidation,
But if there is an error, somehow the library itself knows the index:
for _, e := range errs { e.Namespace() // Parent.childs[0].just_a_field } does anyone know how to get the index?
thanks
@init-database Did you ever solve this? Seems related to this other issue: https://github.com/go-playground/validator/issues/802
Package version eg. v10:
Issue, Question or Enhancement:
This ilustrate my problem:
type Parent struct { Childs []Child
validate:"dive"
}type Child struct { JustAField string
validate:"customValidation"
}func customValidation(fl validator.FieldLevel) bool { // here I want to get the index of child // which currently being validated }
errs := validate.Struct(Parent) I cannot find a method to get current index of child inside customValidation,
But if there is an error, somehow the library itself knows the index:
for _, e := range errs { e.Namespace() // Parent.childs[0].just_a_field } does anyone know how to get the index?
thanks
Code sample, to showcase or reproduce: