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

how to support required_if that Field1 value is one of some value #1317

Open
jobsLee-lcj opened this issue Sep 5, 2024 · 1 comment
Open

Comments

@jobsLee-lcj
Copy link

  • [ ✅] I have looked at the documentation here first?
  • [ ✅] I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

I know that required_if support Field1 is equal to the parameter given like:

// require the field if the Field1 is equal to the parameter given:
Usage: required_if=Field1 foobar

but,what I wanted is required_if=Field1 foobar|test1|test2 when Field1 is a enum string and Field1 value is one of foobar,test1,test2.

Code sample, to showcase or reproduce:

type UpdateIAMUserRequest struct {
	CloudProvider  CloudProvider `json:"cloudProvider" binding:"required,oneof=AlibabaCloud AWS HuaweiCloud QiniuCloud BaiduCloud Volcengine TencentCloud RedCloud"`
	UID            string        `json:"uid" binding:"required"`
	Name           string        `json:"name" binding:"required_if=CloudProvider AWS|BaiduCloud|Volcengine|TencentCloud"`
}
@fiendish
Copy link

fiendish commented Oct 4, 2024

At first I tried validate:"required_if=Field1 foobar|required_if=Field1 test1|required_if=Field1 test2" for this and it didn't work, despite initially seeming like it should. But I guess this is just #922 and the expected difference between "or" vs "and" when talking about the same field can be confusing, but I think in the end "and" is indeed more correct for this and the resolution there makes perfect sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants