Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine required_if with a validation rule #162

Open
OscarVanL opened this issue Aug 25, 2022 · 0 comments
Open

Combine required_if with a validation rule #162

OscarVanL opened this issue Aug 25, 2022 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@OscarVanL
Copy link
Contributor

Hi,

I have a field that is only present if another field has a certain value.

type A struct {
    Type string `validate:"in:B,C"`
    B
    C
}

type B struct {
    ID string `validate:"required_if:A.Type,B|uuid4"
}

So B's ID must be a UUID, but only if A's type is B.

So this is allowed:

A{
    Type: "B", 
    B: {
        ID: "94e48bd3-e990-405e-bd10-304e767cd3fd"
    },
}

But this is not allowed:

A{
    Type: "C", 
    B: {
        ID: "94e48bd3-e990-405e-bd10-304e767cd3fd"
    },
}

And this is not allowed:

A{
    Type: "B", 
    B: {
        ID: ""
    },
}

Do you know how I would achieve this with your library? Thank you!

@inhere inhere added suggestion suggestion question Further information is requested and removed suggestion suggestion labels Aug 25, 2022
@inhere inhere self-assigned this Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants