validator
validator copied to clipboard
How to refer a field in father struct when use 'required_if' tag?
Package version eg. v9, v10:
v10
Issue, Question or Enhancement:
How to refer a field in father struct when use 'required_if' tag?
Code sample, to showcase or reproduce:
type Student struct {
Sex string `validate:"oneof=M F"`
Books []*Book `validate:"required,dive"`
}
type Book struct {
CoverColor string `validate:"required_if=Sex F,oneof=red pink"`
}
I want to make the required_if tag works, but the validator seems ignore the field 'Sex' which I refer to the Student.Sex. And I use Student.Sex to replace Sex but it still doesn't work. So How can I make the required_if tag works when field is it's father's field?
I need too.