validator icon indicating copy to clipboard operation
validator copied to clipboard

How to refer a field in father struct when use 'required_if' tag?

Open wortin opened this issue 4 years ago • 1 comments

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?

wortin avatar Dec 17 '20 10:12 wortin

I need too.

apptut avatar Oct 09 '22 09:10 apptut